118c2affartem/***************************************************************************
218c2affartem * CVSID: $Id$
318c2affartem *
418c2affartem * main.c - Main dbus interface of the hald runner
518c2affartem *
618c2affartem * Copyright (C) 2006 Sjoerd Simons, <sjoerd@luon.net>
73ab06c2Milan Jurik * Copyright (C) 2007 Codethink Ltd. Author Rob Taylor <rob.taylor@codethink.co.uk>
818c2affartem *
918c2affartem * Licensed under the Academic Free License version 2.1
1018c2affartem *
1118c2affartem * This program is free software; you can redistribute it and/or modify
1218c2affartem * it under the terms of the GNU General Public License as published by
1318c2affartem * the Free Software Foundation; either version 2 of the License, or
1418c2affartem * (at your option) any later version.
1518c2affartem *
1618c2affartem * This program is distributed in the hope that it will be useful,
1718c2affartem * but WITHOUT ANY WARRANTY; without even the implied warranty of
1818c2affartem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1918c2affartem * GNU General Public License for more details.
2018c2affartem *
2118c2affartem * You should have received a copy of the GNU General Public License
2218c2affartem * along with this program; if not, write to the Free Software
2318c2affartem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
2418c2affartem *
2518c2affartem **************************************************************************/
2618c2affartem#include <stdio.h>
2718c2affartem#include <stdlib.h>
2818c2affartem#define DBUS_API_SUBJECT_TO_CHANGE
2918c2affartem#include <dbus/dbus-glib-lowlevel.h>
3018c2affartem
3118c2affartem#include <glib.h>
3218c2affartem#include "utils.h"
3318c2affartem#include "runner.h"
3418c2affartem
353ab06c2Milan Jurik#ifndef __GNUC__
363ab06c2Milan Jurik#define __attribute__(x)
373ab06c2Milan Jurik#endif
383ab06c2Milan Jurik
3918c2affartemstatic gboolean
403ab06c2Milan Jurikparse_udi (run_request *r, DBusMessage *msg, DBusMessageIter *iter)
4118c2affartem{
4218c2affartem	char *tmpstr;
4318c2affartem
443ab06c2Milan Jurik	/* Should be the device UDI */
4518c2affartem	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
4618c2affartem		goto malformed;
4718c2affartem	dbus_message_iter_get_basic(iter, &tmpstr);
4818c2affartem	r->udi = g_strdup(tmpstr);
4918c2affartem
503ab06c2Milan Jurik	if (!dbus_message_iter_next(iter))
513ab06c2Milan Jurik		goto malformed;
523ab06c2Milan Jurik
533ab06c2Milan Jurik	return TRUE;
543ab06c2Milan Jurik
553ab06c2Milan Jurikmalformed:
563ab06c2Milan Jurik	return FALSE;
573ab06c2Milan Jurik}
583ab06c2Milan Jurik
593ab06c2Milan Jurikstatic gboolean
603ab06c2Milan Jurikparse_environment(run_request *r, DBusMessage *msg, DBusMessageIter *iter)
613ab06c2Milan Jurik{
623ab06c2Milan Jurik	DBusMessageIter sub_iter;
633ab06c2Milan Jurik	char *tmpstr;
643ab06c2Milan Jurik
653ab06c2Milan Jurik	/* The environment array */
663ab06c2Milan Jurik	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
6718c2affartem		goto malformed;
6818c2affartem	dbus_message_iter_recurse(iter, &sub_iter);
6918c2affartem	/* Add default path for the programs we start */
703ab06c2Milan Jurik#if defined(__FreeBSD__)
713ab06c2Milan 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"));
723ab06c2Milan Jurik#else
7318c2affartem	tmpstr = g_strdup_printf("PATH=/sbin:/usr/sbin:/bin:/usr/bin:%s", getenv("PATH"));
743ab06c2Milan Jurik#endif
75