summaryrefslogtreecommitdiffstats
path: root/bus/main.c
diff options
context:
space:
mode:
authordchen@redhat.com <dchen@dchen.redhat.com>2009-03-03 17:47:58 +1000
committerdchen@redhat.com <dchen@dchen.redhat.com>2009-03-03 17:47:58 +1000
commite370fb079b569980e4f6cf31544d56899afd9911 (patch)
treeaaaf1f8171ceb2e9b5f0d69970e6e7a65dfc96cc /bus/main.c
parent15d0f437874bcca2b9f8f9f1b4e10f1df37322da (diff)
parent9f58762089f0a4b5ec887cd972b4762e7e46455b (diff)
downloadibus-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.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/bus/main.c b/bus/main.c
index 7e53144..cc4507e 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -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);