/* -*- mode: C; c-file-style: "gnu" -*- */ /* dbus-launch.c dbus-launch utility * * Copyright (C) 2007 Ralf Habacker * * Licensed under the Academic Free License version 2.1 * * 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 * */ #include #include #include #define AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE 1 int main(int argc,char **argv) { char dbusDaemonPath[MAX_PATH+1]; char sessionConfPath[MAX_PATH+1]; char command[MAX_PATH]; char *p; PROCESS_INFORMATION pi; STARTUPINFO si; HANDLE h; int result; int showConsole = 0; // set to zero if no console windows should be used char *s = getenv("DBUS_VERBOSE"); int verbose = s && *s != '\0' ? 1 : 0; #ifdef AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE if (verbose) showConsole = 1; #endif GetModuleFileName(NULL,dbusDaemonPath,sizeof(dbusDaemonPath)); if ((p = strrchr(dbusDaemonPath,'\\'))) { *(p+1)= '\0'; strcat(dbusDaemonPath,"dbus-daemon.exe"); } else return 1; // using the session config file is currently the default // calculate full path of session.conf GetModuleFileName(NULL,sessionConfPath,sizeof(sessionConfPath)); if ((p = strstr(sessionConfPath,"\\bin\\"))) { *(p+1)= '\0'; strcat(sessionConfPath,"etc\\session.conf"); } else return 2; // check if we are in the cmake build root h = CreateFile( sessionConfPath, /* LPCTSTR lpFileName*/ 0, /* DWORD dwDesiredAccess */ 0, /* DWORD dwShareMode*/ NULL, /* LPSECURITY_ATTRIBUTES lpSecurityAttributes */ OPEN_EXISTING, /* DWORD dwCreationDisposition */ FILE_ATTRIBUTE_NORMAL, /* DWORD dwFlagsAndAttributes */ NULL /* HANDLE hTemplateFile */ ); if (h == -1 && GetLastError() == ERROR_PATH_NOT_FOUND) { // local copy of session.conf GetModuleFileName(NULL,sessionConfPath,sizeof(sessionConfPath)); if ((p = strstr(sessionConfPath,"\\bin\\"))) { *(p+1)= '\0'; strcat(sessionConfPath,"bus\\session.conf"); } else return 1; } strcpy(command,dbusDaemonPath); strcat(command," --config-file="); strcat(command,sessionConfPath); if (verbose) printf("%s\n",command); memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); result = CreateProcess(NULL, command, 0, 0, TRUE, (showConsole ? CREATE_NEW_CONSOLE : 0) | NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 0; }