upgraded: define __GNU_SOURCE
[project/procd.git] / upgraded / upgraded.c
index 1e4057a782ddf412aa2f7361aa9cadb293f0d77c..357a866d5ccf8e44408a572371f66905c957c7c0 100644 (file)
  * GNU General Public License for more details.
  */
 
+#define _GNU_SOURCE
+
 #include <sys/reboot.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <libubox/uloop.h>
 
@@ -55,12 +58,14 @@ int main(int argc, char **argv)
 {
        pid_t p = getpid();
 
-       chdir("/tmp");
-
        if (p != 1) {
                fprintf(stderr, "this tool needs to run as pid 1\n");
                return -1;
        }
+       if (chdir("/tmp") == -1) {
+               fprintf(stderr, "failed to chdir to /tmp: %s\n", strerror(errno));
+               return -1;
+       }
        if (argc != 2) {
                fprintf(stderr, "sysupgrade stage 2 failed, no folder specified\n");
                return -1;