extern long SS_CopyFile(const char * strFromPath, const char * strToPath);
extern long SS_DeleteFolder(const char * strPath);
extern long SS_DeleteFile(const char * strPath);
-extern int _system_cmd_wait(const char * command);
#endif
// for the sake of simplicity this stays global
static gzFile gz_tar = NULL;
-// the following 6 functions are copied from this same repo, upgrade-apply/main.c
-void fd_cleanup(int *fd)
-{
- if (!fd || *fd < 0)
- return;
- close(*fd);
-}
-
+// the following 5 functions are copied from this same repo, upgrade-apply/main.c
int gzip_open(const char *pathname, int oflags, ...)
{
if (gz_tar != NULL) {
return -1;
}
- __attribute__((cleanup(fd_cleanup))) int inner_fd = open(pathname, O_RDONLY);
- if (inner_fd == -1)
- return -1;
-
gz_tar = gzopen(pathname, "r");
if (gz_tar == NULL)
return -1;
- inner_fd = -1;
return 1;
}
if (s_fd_stderr >= 0)
close(s_fd_stderr);
}
-
-/*-----------------------------------------------------------------------------
- _system_cmd_wait
- ----------------------------------------------------------------------------*/
-int _system_cmd_wait(const char *command)
-{
-
- int pid = 0;
- int status = 0;
- char* const environ[2] = {"DISPLAY=:0", NULL };
-
- if (command == NULL)
- return -1;
-
- pid = fork();
-
- if (pid == -1)
- return -1;
-
- if (pid == 0) {
- char *argv[4];
- argv[0] = "sh";
- argv[1] = "-c";
- argv[2] = (char*)command;
- argv[3] = 0;
- execve("/bin/sh", argv, environ);
- exit(127);
- }
-
- do {
- if (waitpid(pid, &status, 0) == -1) {
- if (errno != EINTR)
- return -1;
- } else {
- return status;
- }
- } while (1);
-}
-
-/*-----------------------------------------------------------------------------
- _system_cmd_nowait
- ----------------------------------------------------------------------------*/
-int _system_cmd_nowait(const char *command)
-{
-
- int pid = 0;
- char* const environ[2] = {"DISPLAY=:0", NULL };
-
- if (command == NULL)
- return -1;
-
- pid = fork();
-
- if (pid == -1)
- return -1;
-
- if (pid == 0) {
- char *argv[4];
- argv[0] = "sh";
- argv[1] = "-c";
- argv[2] = (char*)command;
- argv[3] = 0;
- execve("/bin/sh", argv, environ);
- exit(127);
- }
-
- return 0;
-}
#define _FOTA_UTIL_H_
extern void _exit_stdio(void);
-extern int _system_cmd_wait(const char *command);
-extern int _system_cmd_nowait(const char *command);
#endif /* _FOTA_UTIL_H_ */
dot_pos = strchr(my_opt.archive_file, '.');
len = (dot_pos - my_opt.archive_file);
s_part_info.ua_parti_name = (char*)malloc(sizeof(char) * (len + 1));
+ if (s_part_info.ua_parti_name == NULL) {
+ LOG("memory allocation error: %m (%d)\n", errno);
+ ret = UPI_UPDATE_ERROR;
+ goto Results;
+ }
strncpy(s_part_info.ua_parti_name, my_opt.archive_file, len);
s_part_info.ua_parti_name[len] = '\0';
return -1;
}
- __attribute__((cleanup(fd_cleanup))) int inner_fd = open(pathname, O_RDONLY);
- if (inner_fd == -1)
- return -1;
-
gzip_file = gzopen(pathname, "r");
if (gzip_file == NULL)
return -1;
- inner_fd = -1;
return 1;
}