1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ueventd_firmware_handler.h"
17
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <unistd.h>
21 #include <limits.h>
22 #include "ueventd.h"
23 #define INIT_LOG_TAG "ueventd"
24 #include "init_log.h"
25 #include "securec.h"
26
HandleFimwareDeviceEvent(const struct Uevent * uevent)27 void HandleFimwareDeviceEvent(const struct Uevent *uevent)
28 {
29 char fwLoadingPath[PATH_MAX] = {};
30
31 if (snprintf_s(fwLoadingPath, PATH_MAX, PATH_MAX - 1, "/sys%s/loading", uevent->syspath) == -1) {
32 INIT_LOGE("Failed to build firmware loading path");
33 return;
34 }
35 char realPath[PATH_MAX] = { 0 };
36 realpath(fwLoadingPath, realPath);
37 int fd = open(realPath, O_WRONLY | O_CLOEXEC);
38 if (fd < 0) {
39 INIT_LOGE("Failed to open %s, err = %d", fwLoadingPath, errno);
40 return;
41 }
42
43 char *endCode = "-1";
44 (void)write(fd, "-1", strlen(endCode));
45 close(fd);
46 }
47