summaryrefslogtreecommitdiff
path: root/utils/start-stop-daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/start-stop-daemon.c')
-rw-r--r--utils/start-stop-daemon.c89
1 files changed, 84 insertions, 5 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 88c972663..886fb8872 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -29,6 +29,9 @@
# define OS_Linux
#elif defined(__GNU__)
# define OS_Hurd
+#elif defined(__sun)
+# define OS_sunos
+# include <procfs.h>
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
# define OS_FreeBSD
#elif defined(__NetBSD__)
@@ -67,12 +70,14 @@
#ifdef HAVE_SYS_PROC_H
#include <sys/proc.h>
#endif
+
#ifdef HAVE_SYS_USER_H
#include <sys/user.h>
#endif
#ifdef HAVE_SYS_PSTAT_H
#include <sys/pstat.h>
#endif
+
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
@@ -753,7 +758,7 @@ write_pidfile(const char *filename, pid_t pid)
if (fp == NULL)
fatale("unable to open pidfile '%s' for writing", filename);
- fprintf(fp, "%d\n", pid);
+ fprintf(fp, "%d\n", (int)pid);
if (fclose(fp))
fatale("unable to close pidfile '%s'", filename);
@@ -1714,6 +1719,31 @@ pid_is_exec(pid_t pid, const struct stat *esb)
return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
}
+#elif defined(OS_sunos)
+static bool
+pid_is_exec(pid_t pid, const struct stat *esb)
+{
+ DIR *procdir;
+ struct dirent *entry;
+ char name[_POSIX_PATH_MAX + 1];
+ struct stat sb;
+
+ sprintf(name, "/proc/%d/object", (int)pid);
+ procdir = opendir(name);
+ if (!procdir)
+ return false;
+
+ while ((entry = readdir(procdir)) != NULL) {
+ sprintf(name, "/proc/%d/object/%s", (int)pid, entry->d_name);
+ if (stat(name, &sb) != 0)
+ continue;
+ if (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino)
+ break;
+ }
+ closedir(procdir);
+
+ return (entry != NULL);
+}
#elif defined(OS_AIX)
static bool
pid_is_exec(pid_t pid, const struct stat *esb)
@@ -1881,6 +1911,24 @@ pid_is_child(pid_t pid, pid_t ppid)
return proc_ppid == ppid;
}
+#elif defined(OS_sunos)
+static bool
+pid_is_child(pid_t pid, pid_t ppid)
+{
+ psinfo_t ps;
+ char buf[32];
+ FILE *f;
+
+ sprintf(buf, "/proc/%d/psinfo", (int)pid);
+ f = fopen(buf, "r");
+ if (!f)
+ return false;
+ if (fread(&ps, sizeof(ps), 1, f) != 1)
+ ps.pr_ppid = 0;
+ fclose(f);
+
+ return ps.pr_ppid == ppid;
+}
#elif defined(OS_Hurd)
static bool
pid_is_child(pid_t pid, pid_t ppid)
@@ -1996,6 +2044,18 @@ pid_is_user(pid_t pid, uid_t uid)
return false;
return (sb.st_uid == uid);
}
+#elif defined(OS_sunos)
+static bool
+pid_is_user(pid_t pid, uid_t uid)
+{
+ struct stat sb;
+ char buf[32];
+
+ sprintf(buf, "/proc/%d", (int)pid);
+ if (stat(buf, &sb) != 0)
+ return false;
+ return (sb.st_uid == uid);
+}
#elif defined(OS_Hurd)
static bool
pid_is_user(pid_t pid, uid_t uid)
@@ -2110,6 +2170,25 @@ pid_is_cmd(pid_t pid, const char *name)
return strcmp(comm, name) == 0;
}
+#elif defined(OS_sunos)
+static bool
+pid_is_cmd(pid_t pid, const char *name)
+{
+ char buf[34];
+ FILE *f;
+ psinfo_t p;
+
+ sprintf(buf, "/proc/%d/psinfo", pid);
+ f = fopen(buf, "r");
+ if (!f)
+ return false;
+ if (1 != fread((void *) &p, sizeof(p), 1, f)) {
+ fclose(f);
+ return false;
+ }
+ fclose(f);
+ return !strcmp(p.pr_fname, name);
+}
#elif defined(OS_Hurd)
static bool
pid_is_cmd(pid_t pid, const char *name)
@@ -2321,7 +2400,7 @@ do_pidfile(const char *name)
fatale("unable to open pidfile %s", name);
}
-#if defined(OS_Linux) || defined(OS_Solaris) || defined(OS_AIX)
+#if defined(OS_Linux) || defined(OS_sunos) || defined(OS_AIX)
static enum status_code
do_procinit(void)
{
@@ -2339,7 +2418,7 @@ do_procinit(void)
while ((entry = readdir(procdir)) != NULL) {
enum status_code pid_status;
- if (sscanf(entry->d_name, "%d", &pid) != 1)
+ if (sscanf(entry->d_name, "%d", (int*)&pid) != 1)
continue;
foundany++;
@@ -2651,7 +2730,7 @@ do_stop(int sig_num, int *n_killed, int *n_notkilled)
} else {
if (sig_num)
warning("failed to kill %d: %s\n",
- p->pid, strerror(errno));
+ (int)p->pid, strerror(errno));
(*n_notkilled)++;
}
}
@@ -2667,7 +2746,7 @@ do_stop_summary(int retry_nr)
printf("Stopped %s (pid", what_stop);
for (p = killed; p; p = p->next)
- printf(" %d", p->pid);
+ printf(" %d", (int)p->pid);
putchar(')');
if (retry_nr > 0)
printf(", retry #%d", retry_nr);