1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-launch.c dbus-launch utility
4 * Copyright (C) 2007 Ralf Habacker <ralf.habacker@freenet.de>
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /* save string functions version
33 errno_t strcat_s(char *dest, int size, char *src)
35 assert(strlen(dest) + strlen(src) +1 <= size);
40 errno_t strcpy_s(char *dest, int size, char *src)
42 assert(strlen(src) +1 <= size);
48 /* TODO: use unicode version as suggested by Tor Lillqvist */
50 #define AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE 1
52 int main(int argc,char **argv)
54 char dbusDaemonPath[MAX_PATH*2+1];
55 char command[MAX_PATH*2+1];
60 char *s = getenv("DBUS_VERBOSE");
61 int verbose = s && *s != '\0' ? 1 : 0;
62 PROCESS_INFORMATION pi;
66 #ifdef AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE
70 GetModuleFileName(NULL,dbusDaemonPath,sizeof(dbusDaemonPath));
71 /* check for debug version */
72 if (strstr(dbusDaemonPath,"dbus-launchd.exe"))
73 daemon_name = "dbus-daemond.exe";
75 daemon_name = "dbus-daemon.exe";
76 if ((p = strrchr(dbusDaemonPath,'\\')))
79 strcat_s(dbusDaemonPath,sizeof(dbusDaemonPath),daemon_name);
84 fprintf(stderr,"error: could not extract path from current applications module filename\n");
88 strcpy_s(command,sizeof(command),dbusDaemonPath);
89 strcat_s(command,sizeof(command)," --session");
91 fprintf(stderr,"%s\n",command);
93 memset(&si, 0, sizeof(si));
94 memset(&pi, 0, sizeof(pi));
97 result = CreateProcess(NULL,
102 (showConsole ? CREATE_NEW_CONSOLE : 0) | NORMAL_PRIORITY_CLASS,
108 CloseHandle(pi.hProcess);
109 CloseHandle(pi.hThread);
114 fprintf(stderr,"could not start dbus-daemon error=%d",GetLastError());