system: always support staged sysupgrade
[project/procd.git] / trace / trace.c
index c6f32d7..fdffaba 100644 (file)
@@ -14,9 +14,9 @@
 #define _GNU_SOURCE
 #include <stddef.h>
 #include <sys/ptrace.h>
+#include <sys/types.h>
 #include <sys/user.h>
 #include <sys/wait.h>
-#include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -42,6 +42,8 @@
 # define EF_REG2       8
 # endif
 #define reg_syscall_nr (EF_REG2 / 4)
+#elif defined(__arm__)
+#define reg_syscall_nr _offsetof(struct user, regs.uregs[7])
 #else
 #error tracing is not supported on this architecture
 #endif
@@ -51,7 +53,7 @@
 } while (0)
 
 #define ERROR(fmt, ...) do { \
-       syslog(0, "utrace: "fmt, ## __VA_ARGS__); \
+       syslog(LOG_ERR, "utrace: "fmt, ## __VA_ARGS__); \
        fprintf(stderr, "utrace: "fmt, ## __VA_ARGS__); \
 } while (0)
 
@@ -174,7 +176,7 @@ int main(int argc, char **argv, char **envp)
        if (child == 0) {
                char **_argv = calloc(argc + 1, sizeof(char *));
                char **_envp;
-               char preload[] = "LD_PRELOAD=/lib/libpreload-trace.so";
+               char *preload = "LD_PRELOAD=/lib/libpreload-trace.so";
                int envc = 1;
                int ret;
 
@@ -185,10 +187,13 @@ int main(int argc, char **argv, char **envp)
 
                _envp = calloc(envc, sizeof(char *));
                memcpy(&_envp[1], _envp, envc * sizeof(char *));
-               *envp = preload;
+               *_envp = preload;
 
-               ret = execve(_argv[0], _argv, envp);
+               ret = execve(_argv[0], _argv, _envp);
                ERROR("failed to exec %s: %s\n", _argv[0], strerror(errno));
+
+               free(_argv);
+               free(_envp);
                return ret;
        }
 
@@ -214,7 +219,8 @@ int main(int argc, char **argv, char **envp)
        uloop_done();
 
        if (!json)
-               asprintf(&json, "/tmp/%s.%u.json", basename(*argv), child);
+               if (asprintf(&json, "/tmp/%s.%u.json", basename(*argv), child) < 0)
+                       ERROR("failed to allocate output path: %s\n", strerror(errno));
 
        print_syscalls(policy, json);