xref: /illumos-gate/usr/src/cmd/hal/hald-runner/main.c (revision 3ab06c27)
118c2aff7Sartem /***************************************************************************
218c2aff7Sartem  * CVSID: $Id$
318c2aff7Sartem  *
418c2aff7Sartem  * main.c - Main dbus interface of the hald runner
518c2aff7Sartem  *
618c2aff7Sartem  * Copyright (C) 2006 Sjoerd Simons, <sjoerd@luon.net>
7*3ab06c27SMilan Jurik  * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
818c2aff7Sartem  *
918c2aff7Sartem  * Licensed under the Academic Free License version 2.1
1018c2aff7Sartem  *
1118c2aff7Sartem  * This program is free software; you can redistribute it and/or modify
1218c2aff7Sartem  * it under the terms of the GNU General Public License as published by
1318c2aff7Sartem  * the Free Software Foundation; either version 2 of the License, or
1418c2aff7Sartem  * (at your option) any later version.
1518c2aff7Sartem  *
1618c2aff7Sartem  * This program is distributed in the hope that it will be useful,
1718c2aff7Sartem  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1818c2aff7Sartem  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1918c2aff7Sartem  * GNU General Public License for more details.
2018c2aff7Sartem  *
2118c2aff7Sartem  * You should have received a copy of the GNU General Public License
2218c2aff7Sartem  * along with this program; if not, write to the Free Software
2318c2aff7Sartem  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
2418c2aff7Sartem  *
2518c2aff7Sartem  **************************************************************************/
2618c2aff7Sartem #include <stdio.h>
2718c2aff7Sartem #include <stdlib.h>
2818c2aff7Sartem #define DBUS_API_SUBJECT_TO_CHANGE
2918c2aff7Sartem #include <dbus/dbus-glib-lowlevel.h>
3018c2aff7Sartem 
3118c2aff7Sartem #include <glib.h>
3218c2aff7Sartem #include "utils.h"
3318c2aff7Sartem #include "runner.h"
3418c2aff7Sartem 
35*3ab06c27SMilan Jurik #ifndef __GNUC__
36*3ab06c27SMilan Jurik #define __attribute__(x)
37*3ab06c27SMilan Jurik #endif
38*3ab06c27SMilan Jurik 
3918c2aff7Sartem static gboolean
parse_udi(run_request * r,DBusMessage * msg,DBusMessageIter * iter)40*3ab06c27SMilan Jurik parse_udi (run_request *r, DBusMessage *msg, DBusMessageIter *iter)
4118c2aff7Sartem {
4218c2aff7Sartem 	char *tmpstr;
4318c2aff7Sartem 
44*3ab06c27SMilan Jurik 	/* Should be the device UDI */
4518c2aff7Sartem 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
4618c2aff7Sartem 		goto malformed;
4718c2aff7Sartem 	dbus_message_iter_get_basic(iter, &tmpstr);
4818c2aff7Sartem 	r->udi = g_strdup(tmpstr);
4918c2aff7Sartem 
50*3ab06c27SMilan Jurik 	if (!dbus_message_iter_next(iter))
51*3ab06c27SMilan Jurik 		goto malformed;
52*3ab06c27SMilan Jurik 
53*3ab06c27SMilan Jurik 	return TRUE;
54*3ab06c27SMilan Jurik 
55*3ab06c27SMilan Jurik malformed:
56*3ab06c27SMilan Jurik 	return FALSE;
57*3ab06c27SMilan Jurik }
58*3ab06c27SMilan Jurik 
59*3ab06c27SMilan Jurik static gboolean
parse_environment(run_request * r,DBusMessage * msg,DBusMessageIter * iter)60*3ab06c27SMilan Jurik parse_environment(run_request *r, DBusMessage *msg, DBusMessageIter *iter)
61*3ab06c27SMilan Jurik {
62*3ab06c27SMilan Jurik 	DBusMessageIter sub_iter;
63*3ab06c27SMilan Jurik 	char *tmpstr;
64*3ab06c27SMilan Jurik 
65*3ab06c27SMilan Jurik 	/* The environment array */
66*3ab06c27SMilan Jurik 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
6718c2aff7Sartem 		goto malformed;
6818c2aff7Sartem 	dbus_message_iter_recurse(iter, &sub_iter);
6918c2aff7Sartem 	/* Add default path for the programs we start */
70*3ab06c27SMilan Jurik #if defined(__FreeBSD__)
71*3ab06c27SMilan Jurik 	tmpstr = g_strdup_printf("PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/X11R6/sbin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:%s", getenv("PATH"));
72