diff options
author | William Jon McCann <mccann@jhu.edu> | 2007-08-16 22:29:18 -0400 |
---|---|---|
committer | William Jon McCann <mccann@jhu.edu> | 2007-08-16 22:29:18 -0400 |
commit | fcb0f32632f74950c361a0a23128ebca05efdca0 (patch) | |
tree | 4e496846ea2b4327e4f8e3dbf4aee74b4321ddc3 /src | |
parent | e56a95f64c9c9f57adebf6cb3e6c88790cec40e4 (diff) |
move all proc stuff into ck-sysdeps
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 23 | ||||
-rw-r--r-- | src/ck-manager.c | 52 | ||||
-rw-r--r-- | src/ck-sysdeps-linux.c (renamed from src/proc-linux.c) | 60 | ||||
-rw-r--r-- | src/ck-sysdeps-solaris.c (renamed from src/proc-solaris.c) | 40 | ||||
-rw-r--r-- | src/ck-sysdeps.h | 49 | ||||
-rw-r--r-- | src/proc.h | 48 |
6 files changed, 137 insertions, 135 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c63abf3..948b247 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,27 +24,27 @@ INCLUDES = \ $(NULL) noinst_LTLIBRARIES = \ - libckproc.la \ + libck.la \ $(NULL) -libckproc_la_SOURCES = \ - proc.h \ +libck_la_SOURCES = \ + ck-sysdeps.h \ $(NULL) if CK_COMPILE_LINUX -libckproc_la_SOURCES += \ - proc-linux.c \ +libck_la_SOURCES += \ + ck-sysdeps-linux.c \ $(NULL) endif if CK_COMPILE_SOLARIS -libckproc_la_SOURCES += \ - proc-solaris.c \ +libck_la_SOURCES += \ + ck-sysdeps-solaris.c \ $(NULL) endif -EXTRA_libckproc_la_SOURCES = \ - proc-linux.c \ - proc-solaris.c \ +EXTRA_libck_la_SOURCES = \ + ck-sysdeps-linux.c \ + ck-sysdeps-solaris.c \ $(NULL) sbin_PROGRAMS = \ @@ -91,7 +91,6 @@ console_kit_daemon_SOURCES = \ ck-log.h \ ck-log.c \ getfd.c \ - proc.h \ $(BUILT_SOURCES) \ $(NULL) @@ -110,7 +109,7 @@ EXTRA_console_kit_daemon_SOURCES = \ console_kit_daemon_LDADD = \ $(CONSOLE_KIT_LIBS) \ - libckproc.la \ + libck.la \ $(NULL) noinst_PROGRAMS = \ diff --git a/src/ck-manager.c b/src/ck-manager.c index 3007437..506249b 100644 --- a/src/ck-manager.c +++ b/src/ck-manager.c @@ -43,7 +43,7 @@ #include "ck-job.h" #include "ck-marshal.h" -#include "proc.h" +#include "ck-sysdeps.h" #define CK_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CK_TYPE_MANAGER, CkManagerPrivate)) @@ -933,15 +933,15 @@ ck_manager_get_session_for_cookie (CkManager *manager, const char *cookie, DBusGMethodInvocation *context) { - gboolean res; - char *sender; - uid_t calling_uid; - pid_t calling_pid; - proc_stat_t *stat; - char *ssid; - CkSession *session; - LeaderInfo *leader_info; - GError *local_error; + gboolean res; + char *sender; + uid_t calling_uid; + pid_t calling_pid; + CkProcessStat *stat; + char *ssid; + CkSession *session; + LeaderInfo *leader_info; + GError *local_error; ssid = NULL; @@ -964,7 +964,7 @@ ck_manager_get_session_for_cookie (CkManager *manager, } local_error = NULL; - res = proc_stat_new_for_pid (calling_pid, &stat, &local_error); + res = ck_process_stat_new_for_unix_pid (calling_pid, &stat, &local_error); if (! res) { GError *error; error = g_error_new (CK_MANAGER_ERROR, @@ -982,7 +982,7 @@ ck_manager_get_session_for_cookie (CkManager *manager, } /* FIXME: should we restrict this by uid? */ - proc_stat_free (stat); + ck_process_stat_free (stat); leader_info = g_hash_table_lookup (manager->priv->leaders, cookie); if (leader_info == NULL) { @@ -1023,7 +1023,7 @@ get_cookie_for_pid (CkManager *manager, /* FIXME: need a better way to get the cookie */ - cookie = proc_pid_get_env (pid, "XDG_SESSION_COOKIE"); + cookie = ck_unix_pid_get_env (pid, "XDG_SESSION_COOKIE"); return cookie; } @@ -1040,13 +1040,13 @@ ck_manager_get_session_for_unix_process (CkManager *manager, guint pid, DBusGMethodInvocation *context) { - gboolean res; - char *sender; - uid_t calling_uid; - pid_t calling_pid; - proc_stat_t *stat; - char *cookie; - GError *error; + gboolean res; + char *sender; + uid_t calling_uid; + pid_t calling_pid; + CkProcessStat *stat; + char *cookie; + GError *error; sender = dbus_g_method_get_sender (context); @@ -1067,7 +1067,7 @@ ck_manager_get_session_for_unix_process (CkManager *manager, } error = NULL; - res = proc_stat_new_for_pid (calling_pid, &stat, &error); + res = ck_process_stat_new_for_unix_pid (calling_pid, &stat, &error); if (! res) { GError *error; g_debug ("stat on pid %d failed", calling_pid); @@ -1082,7 +1082,7 @@ ck_manager_get_session_for_unix_process (CkManager *manager, /* FIXME: check stuff? */ - proc_stat_free (stat); + ck_process_stat_free (stat); cookie = get_cookie_for_pid (manager, pid); if (cookie == NULL) { @@ -1572,9 +1572,9 @@ add_seat_for_file (CkManager *manager, static gboolean load_seats_from_dir (CkManager *manager) { - GDir *d; - GError *error; - char *file; + GDir *d; + GError *error; + const char *file; error = NULL; d = g_dir_open (CK_SEAT_DIR, @@ -1594,6 +1594,8 @@ load_seats_from_dir (CkManager *manager) } g_dir_close (d); + + return TRUE; } static void diff --git a/src/proc-linux.c b/src/ck-sysdeps-linux.c index d704e18..624bfc4 100644 --- a/src/proc-linux.c +++ b/src/ck-sysdeps-linux.c @@ -32,10 +32,10 @@ #include <paths.h> #endif /* HAVE_PATHS_H */ -#include "proc.h" +#include "ck-sysdeps.h" /* adapted from procps */ -struct _proc_stat_t +struct _CkProcessStat { int pid; int ppid; /* stat,status pid of parent process */ @@ -111,7 +111,7 @@ load_drivers (void) buf[bytes] = '\0'; p = buf; - while ((p = strstr (p, " " _PATH_DEV))){ + while ((p = strstr (p, " " _PATH_DEV))) { tty_map_node *tmn; int len; char *end; @@ -263,7 +263,7 @@ link_name (guint maj, } pid_t -proc_stat_get_ppid (proc_stat_t *stat) +ck_process_stat_get_ppid (CkProcessStat *stat) { g_return_val_if_fail (stat != NULL, -1); @@ -271,7 +271,7 @@ proc_stat_get_ppid (proc_stat_t *stat) } char * -proc_stat_get_cmd (proc_stat_t *stat) +ck_process_stat_get_cmd (CkProcessStat *stat) { g_return_val_if_fail (stat != NULL, NULL); @@ -280,7 +280,7 @@ proc_stat_get_cmd (proc_stat_t *stat) /* adapted from procps */ char * -proc_stat_get_tty (proc_stat_t *stat) +ck_process_stat_get_tty (CkProcessStat *stat) { guint dev; char *tty; @@ -328,8 +328,8 @@ proc_stat_get_tty (proc_stat_t *stat) #define KLF "l" /* adapted from procps */ static void -stat2proc (const char *S, - proc_stat_t *P) +stat2proc (const char *S, + CkProcessStat *P) { unsigned num; char * tmp; @@ -392,16 +392,16 @@ stat2proc (const char *S, } gboolean -proc_stat_new_for_pid (pid_t pid, - proc_stat_t **stat, - GError **error) +ck_process_stat_new_for_unix_pid (pid_t pid, + CkProcessStat **stat, + GError **error) { - char *path; - char *contents; - gsize length; - gboolean res; - GError *local_error; - proc_stat_t *proc; + char *path; + char *contents; + gsize length; + gboolean res; + GError *local_error; + CkProcessStat *proc; g_return_val_if_fail (pid > 1, FALSE); @@ -418,7 +418,7 @@ proc_stat_new_for_pid (pid_t pid, &length, &local_error); if (res) { - proc = g_new0 (proc_stat_t, 1); + proc = g_new0 (CkProcessStat, 1); proc->pid = pid; stat2proc (contents, proc); *stat = proc; @@ -434,13 +434,13 @@ proc_stat_new_for_pid (pid_t pid, } void -proc_stat_free (proc_stat_t *stat) +ck_process_stat_free (CkProcessStat *stat) { g_free (stat); } GHashTable * -proc_pid_get_env_hash (pid_t pid) +ck_unix_pid_get_env_hash (pid_t pid) { char *path; gboolean res; @@ -498,8 +498,8 @@ proc_pid_get_env_hash (pid_t pid) } char * -proc_pid_get_env (pid_t pid, - const char *var) +ck_unix_pid_get_env (pid_t pid, + const char *var) { char *path; gboolean res; @@ -558,7 +558,7 @@ proc_pid_get_env (pid_t pid, } uid_t -proc_pid_get_uid (pid_t pid) +ck_unix_pid_get_uid (pid_t pid) { struct stat st; char *path; @@ -581,24 +581,24 @@ proc_pid_get_uid (pid_t pid) } pid_t -proc_pid_get_ppid (pid_t pid) +ck_unix_pid_get_ppid (pid_t pid) { - int ppid; - gboolean res; - proc_stat_t *stat; + int ppid; + gboolean res; + CkProcessStat *stat; g_return_val_if_fail (pid > 1, 0); ppid = -1; - res = proc_stat_new_for_pid (pid, &stat, NULL); + res = ck_process_stat_new_for_unix_pid (pid, &stat, NULL); if (! res) { goto out; } - ppid = proc_stat_get_ppid (stat); + ppid = ck_process_stat_get_ppid (stat); - proc_stat_free (stat); + ck_process_stat_free (stat); out: return ppid; diff --git a/src/proc-solaris.c b/src/ck-sysdeps-solaris.c index f95c042..caea4c7 100644 --- a/src/proc-solaris.c +++ b/src/ck-sysdeps-solaris.c @@ -38,10 +38,10 @@ #include <sys/procfs.h> #define NO_TTY_VALUE DEV_ENCODE(-1,-1) -#include "proc.h" +#include "ck-sysdeps.h" /* adapted from procps */ -struct _proc_stat_t +struct _CkProcessStat { int pid; int ppid; /* stat,status pid of parent process */ @@ -84,7 +84,7 @@ struct _proc_stat_t }; pid_t -proc_stat_get_ppid (proc_stat_t *stat) +ck_process_stat_get_ppid (CkProcessStat *stat) { g_return_val_if_fail (stat != NULL, -1); @@ -92,7 +92,7 @@ proc_stat_get_ppid (proc_stat_t *stat) } char * -proc_stat_get_cmd (proc_stat_t *stat) +ck_process_stat_get_cmd (CkProcessStat *stat) { g_return_val_if_fail (stat != NULL, NULL); @@ -101,7 +101,7 @@ proc_stat_get_cmd (proc_stat_t *stat) /* adapted from procps */ char * -proc_stat_get_tty (proc_stat_t *stat) +ck_process_stat_get_tty (CkProcessStat *stat) { guint dev; char *tty; @@ -117,7 +117,7 @@ proc_stat_get_tty (proc_stat_t *stat) /* return 1 if it works, or 0 for failure */ static gboolean stat2proc (pid_t pid, - proc_stat_t *P) + CkProcessStat *P) { struct psinfo p; char buf[32]; @@ -187,16 +187,16 @@ stat2proc (pid_t pid, } gboolean -proc_stat_new_for_pid (pid_t pid, - proc_stat_t **stat, - GError **error) +ck_process_stat_new_for_unix_pid (pid_t pid, + CkProcessStat **stat, + GError **error) { char *path; char *contents; gsize length; gboolean res; GError *local_error; - proc_stat_t *proc; + CkProcessStat *proc; g_return_val_if_fail (pid > 1, FALSE); @@ -204,7 +204,7 @@ proc_stat_new_for_pid (pid_t pid, return FALSE; } - proc = g_new0 (proc_stat_t, 1); + proc = g_new0 (CkProcessStat, 1); proc->pid = pid; res = stat2proc (pid, proc); if (res) { @@ -218,7 +218,7 @@ proc_stat_new_for_pid (pid_t pid, } void -proc_stat_free (proc_stat_t *stat) +ck_process_stat_free (CkProcessStat *stat) { g_free (stat); } @@ -228,13 +228,13 @@ proc_pid_get_env_hash (pid_t pid) { GHashTable *hash; gboolean res; - proc_stat_t *stat; + CkProcessStat *stat; char *env[400]; char buf[BUFSIZ]; int fd; int i; - res = proc_stat_new_for_pid (pid, &stat, NULL); + res = ck_process_stat_new_for_unix_pid (pid, &stat, NULL); if (! res) { goto out; } @@ -302,22 +302,22 @@ proc_pid_get_uid (pid_t pid) pid_t proc_pid_get_ppid (pid_t pid) { - int ppid; - gboolean res; - proc_stat_t *stat; + int ppid; + gboolean res; + CkProcessStat *stat; g_return_val_if_fail (pid > 1, 0); ppid = -1; - res = proc_stat_new_for_pid (pid, &stat, NULL); + res = ck_process_stat_new_for_unix_pid (pid, &stat, NULL); if (! res) { goto out; } - ppid = proc_stat_get_ppid (stat); + ppid = ck_process_stat_get_ppid (stat); - proc_stat_free (stat); + ck_process_stat_free (stat); out: return ppid; diff --git a/src/ck-sysdeps.h b/src/ck-sysdeps.h new file mode 100644 index 0000000..7a5f768 --- /dev/null +++ b/src/ck-sysdeps.h @@ -0,0 +1,49 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2006 William Jon McCann <mccann@jhu.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __CK_SYSDEPS_H +#define __CK_SYSDEPS_H + +#include <glib.h> + +G_BEGIN_DECLS + +typedef struct _CkProcessStat CkProcessStat; + +gboolean ck_process_stat_new_for_unix_pid (pid_t pid, + CkProcessStat **stat, + GError **error); +pid_t ck_process_stat_get_ppid (CkProcessStat *stat); +char *ck_process_stat_get_tty (CkProcessStat *stat); +char *ck_process_stat_get_cmd (CkProcessStat *stat); +void ck_process_stat_free (CkProcessStat *stat); + + +char *ck_unix_pid_get_env (pid_t pid, + const char *var); + +GHashTable *ck_unix_pid_get_env_hash (pid_t pid); + +pid_t ck_unix_pid_get_ppid (pid_t pid); +uid_t ck_unix_pid_get_uid (pid_t pid); + +G_END_DECLS + +#endif /* __CK_SYSDEPS_H */ diff --git a/src/proc.h b/src/proc.h deleted file mode 100644 index 8c3fc64..0000000 --- a/src/proc.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2006 William Jon McCann <mccann@jhu.edu> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __PROC_H -#define __PROC_H - -#include <glib.h> - -G_BEGIN_DECLS - -typedef struct _proc_stat_t proc_stat_t; - -gboolean proc_stat_new_for_pid (pid_t pid, - proc_stat_t **stat, - GError **error); -pid_t proc_stat_get_ppid (proc_stat_t *stat); -char *proc_stat_get_tty (proc_stat_t *stat); -char *proc_stat_get_cmd (proc_stat_t *stat); -void proc_stat_free (proc_stat_t *stat); - -char *proc_pid_get_env (pid_t pid, - const char *var); - -GHashTable *proc_pid_get_env_hash (pid_t pid); - -pid_t proc_pid_get_ppid (pid_t pid); -uid_t proc_pid_get_uid (pid_t pid); - -G_END_DECLS - -#endif /* __PROC_H */ |