diff options
author | dchen@redhat.com <dchen@dchen.redhat.com> | 2009-03-03 17:47:58 +1000 |
---|---|---|
committer | dchen@redhat.com <dchen@dchen.redhat.com> | 2009-03-03 17:47:58 +1000 |
commit | e370fb079b569980e4f6cf31544d56899afd9911 (patch) | |
tree | aaaf1f8171ceb2e9b5f0d69970e6e7a65dfc96cc /bus/main.c | |
parent | 15d0f437874bcca2b9f8f9f1b4e10f1df37322da (diff) | |
parent | 9f58762089f0a4b5ec887cd972b4762e7e46455b (diff) | |
download | ibus-e370fb079b569980e4f6cf31544d56899afd9911.tar.gz ibus-e370fb079b569980e4f6cf31544d56899afd9911.tar.xz ibus-e370fb079b569980e4f6cf31544d56899afd9911.zip |
Merge branch 'master' of git://github.com/phuang/ibus
Diffstat (limited to 'bus/main.c')
-rw-r--r-- | bus/main.c | 49 |
1 files changed, 47 insertions, 2 deletions
@@ -17,9 +17,11 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - +#include <config.h> #include <unistd.h> #include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> #include <pwd.h> #include <stdlib.h> #include <locale.h> @@ -87,6 +89,49 @@ execute_cmdline (const gchar *cmdline) return TRUE; } +#ifndef HAVE_DAEMON +static void +closeall (gint fd) +{ + gint fdlimit = sysconf(_SC_OPEN_MAX); + + while (fd < fdlimit) { + close(fd++); + } +} + +static gint +daemon (gint nochdir, gint noclose) +{ + switch (fork()) { + case 0: break; + case -1: return -1; + default: _exit(0); + } + + if (setsid() < 0) { + return -1; + } + + switch (fork()) { + case 0: break; + case -1: return -1; + default: _exit(0); + } + + if (!nochdir) { + chdir("/"); + } + + if (!noclose) { + closeall(0); + open("/dev/null",O_RDWR); + dup(0); dup(0); + } + return 0; +} +#endif + gint main (gint argc, gchar **argv) { @@ -110,7 +155,7 @@ main (gint argc, gchar **argv) /* check uid */ { - gchar *username = ibus_get_user_name (); + const gchar *username = ibus_get_user_name (); uid_t uid = getuid (); struct passwd *pwd = getpwuid (uid); |