1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #if defined __MINGW32__ || (defined _MSC_VER && _MSC_VER <= 1310)
30 /* save string functions version
34 errno_t strcat_s(char *dest, size_t size, char *src)
36 assert(strlen(dest) + strlen(src) +1 <= size);
41 errno_t strcpy_s(char *dest, size_t size, char *src)
43 assert(strlen(src) +1 <= size);
49 /* TODO: Use Unicode APIs */
51 /* TODO: This Windows version of dbus-launch is curretly rather
52 * pointless as it doesn't take the same command-line options as the
53 * UNIX dbus-launch does. A main point of the dbus-launch command is
54 * to pass it for instance a --config-file option to make the started
55 * dbus-daemon use that config file.
57 * This version also doesn't print out any information, which is a
58 * main point of the UNIX one. It should at least support the
59 * --sh-syntax option, and maybe also a --cmd-syntax to print out the
60 * variable settings in cmd.exe syntax?
63 #define AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE 1
65 int main(int argc,char **argv)
67 char dbusDaemonPath[MAX_PATH*2+1];
68 char command[MAX_PATH*2+1];
73 char *s = getenv("DBUS_VERBOSE");
74 int verbose = s && *s != '\0' ? 1 : 0;
75 PROCESS_INFORMATION pi;
79 #ifdef AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE
83 GetModuleFileName(NULL,dbusDaemonPath,sizeof(dbusDaemonPath));
86 daemon_name = "dbus-daemond.exe";
88 daemon_name = "dbus-daemon.exe";
90 if ((p = _mbsrchr (dbusDaemonPath, '\\')))
93 strcat_s(dbusDaemonPath,sizeof(dbusDaemonPath),daemon_name);
98 fprintf(stderr,"error: could not extract path from current applications module filename\n");
102 strcpy_s(command,sizeof(command),dbusDaemonPath);
103 strcat_s(command,sizeof(command)," --session");
105 fprintf(stderr,"%s\n",command);
107 memset(&si, 0, sizeof(si));
108 memset(&pi, 0, sizeof(pi));
111 result = CreateProcess(NULL,
116 (showConsole ? CREATE_NEW_CONSOLE : 0) | NORMAL_PRIORITY_CLASS,
122 CloseHandle(pi.hProcess);
123 CloseHandle(pi.hThread);
128 fprintf(stderr, "Could not start dbus-daemon error=%d",GetLastError());