]> git.proxmox.com Git - mirror_frr.git/blobdiff - tools/start-stop-daemon.c
Merge pull request #3378 from opensourcerouting/remove-config-lock
[mirror_frr.git] / tools / start-stop-daemon.c
index de58e0a20e2b75756bc168828a9563872ad033da..f2a1e9434bc9d2d848ec4a6591844986444c59f8 100644 (file)
  *   the whole automake/config.h dance.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #ifdef HAVE_LXC
 #define _GNU_SOURCE
 #include <sched.h>
 #endif /* HAVE_LXC */
 
 #include <stddef.h>
+#undef VERSION
 #define VERSION "1.9.18"
 
 #define MIN_POLL_INTERVAL 20000 /*us*/
@@ -602,7 +607,7 @@ static int pid_is_exec(pid_t pid, const struct stat *esb)
        struct stat sb;
        char buf[32];
 
-       sprintf(buf, "/proc/%d/exe", pid);
+       sprintf(buf, "/proc/%ld/exe", (long)pid);
        if (stat(buf, &sb) != 0)
                return 0;
        return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
@@ -614,7 +619,7 @@ static int pid_is_user(pid_t pid, uid_t uid)
        struct stat sb;
        char buf[32];
 
-       sprintf(buf, "/proc/%d", pid);
+       sprintf(buf, "/proc/%ld", (long)pid);
        if (stat(buf, &sb) != 0)
                return 0;
        return (sb.st_uid == uid);
@@ -627,7 +632,7 @@ static int pid_is_cmd(pid_t pid, const char *name)
        FILE *f;
        int c;
 
-       sprintf(buf, "/proc/%d/stat", pid);
+       sprintf(buf, "/proc/%ld/stat", (long)pid);
        f = fopen(buf, "r");
        if (!f)
                return 0;
@@ -659,12 +664,12 @@ static void check(pid_t pid)
 static void do_pidfile(const char *name)
 {
        FILE *f;
-       pid_t pid;
+       long pid;
 
        f = fopen(name, "r");
        if (f) {
-               if (fscanf(f, "%d", &pid) == 1)
-                       check(pid);
+               if (fscanf(f, "%ld", &pid) == 1)
+                       check((pid_t)pid);
                fclose(f);
        } else if (errno != ENOENT)
                fatal("open pidfile %s: %s", name, strerror(errno));
@@ -677,7 +682,7 @@ static void do_procinit(void)
        DIR *procdir;
        struct dirent *entry;
        int foundany;
-       pid_t pid;
+       long pid;
 
        procdir = opendir("/proc");
        if (!procdir)
@@ -685,10 +690,10 @@ static void do_procinit(void)
 
        foundany = 0;
        while ((entry = readdir(procdir)) != NULL) {
-               if (sscanf(entry->d_name, "%d", &pid) != 1)
+               if (sscanf(entry->d_name, "%ld", &pid) != 1)
                        continue;
                foundany++;
-               check(pid);
+               check((pid_t)pid);
        }
        closedir(procdir);
        if (!foundany)
@@ -723,21 +728,21 @@ static void do_stop(int signal_nr, int quietmode, int *n_killed,
 
        for (p = found; p; p = p->next) {
                if (testmode)
-                       printf("Would send signal %d to %d.\n", signal_nr,
-                              p->pid);
+                       printf("Would send signal %d to %ld.\n", signal_nr,
+                              (long)p->pid);
                else if (kill(p->pid, signal_nr) == 0) {
                        push(&killed, p->pid);
                        (*n_killed)++;
                } else {
-                       printf("%s: warning: failed to kill %d: %s\n", progname,
-                              p->pid, strerror(errno));
+                       printf("%s: warning: failed to kill %ld: %s\n",
+                              progname, (long)p->pid, strerror(errno));
                        (*n_notkilled)++;
                }
        }
        if (quietmode < 0 && killed) {
                printf("Stopped %s (pid", what_stop);
                for (p = killed; p; p = p->next)
-                       printf(" %d", p->pid);
+                       printf(" %ld", (long)p->pid);
                putchar(')');
                if (retry_nr > 0)
                        printf(", retry #%d", retry_nr);
@@ -1008,7 +1013,7 @@ int main(int argc, char **argv)
        if (background) { /* ok, we need to detach this process */
                int i, fd;
                if (quietmode < 0)
-                       printf("Detatching to start %s...", startas);
+                       printf("Detaching to start %s...", startas);
                i = fork();
                if (i < 0) {
                        fatal("Unable to fork.\n");
@@ -1025,7 +1030,9 @@ int main(int argc, char **argv)
                /* change tty */
                fd = open("/dev/tty", O_RDWR);
                if (fd >= 0) {
-                       ioctl(fd, TIOCNOTTY, 0);
+                       if (ioctl(fd, TIOCNOTTY, 0) < 0)
+                               printf("ioctl TIOCNOTTY failed: %s\n",
+                                      strerror(errno));
                        close(fd);
                }
                chdir("/");
@@ -1050,7 +1057,7 @@ int main(int argc, char **argv)
                if (pidf == NULL)
                        fatal("Unable to open pidfile `%s' for writing: %s",
                              pidfile, strerror(errno));
-               fprintf(pidf, "%d\n", pidt);
+               fprintf(pidf, "%ld\n", (long)pidt);
                fclose(pidf);
        }
        set_namespaces();