48
if(argc == 1) return -1;
50
52
dbus_error_init (&error);
52
if((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
54
if ((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
54
56
if ((hal_ctx = libhal_ctx_new ()) == NULL) {
55
fprintf (stderr, "error: libhal_ctx_new\n");
57
syslog (LOG_INFO, "error: libhal_ctx_new\n");
59
61
if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
60
fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
62
syslog (LOG_INFO, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
61
63
LIBHAL_FREE_DBUS_ERROR (&error);
65
67
if (!libhal_ctx_init (hal_ctx, &error)) {
66
fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
68
syslog (LOG_INFO, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
67
69
LIBHAL_FREE_DBUS_ERROR (&error);
72
74
parent = libhal_device_get_property_string (hal_ctx, udi, "info.parent", &error);
73
75
udis = libhal_manager_find_device_string_match (hal_ctx, "info.parent", parent, &num_udis, &error);
77
if( argc==2 && strcmp("getrfkill",argv[1])==0) {
79
for (i = 0; i < num_udis; i++) {
82
if (strcmp (udis[i], udi) == 0)
85
iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
87
path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
89
if ((fd = fopen (path, "r")) == NULL) {
92
if (fgets (buf, sizeof (buf), fd) == NULL) {
97
kill_status = strtol (buf, NULL, 10);
99
/* syslog (LOG_INFO, "'%s' returned %d", path, kill_status); */
101
switch(kill_status) {
117
libhal_free_string (iface);
122
if (argc == 3 && strcmp ("setrfkill", argv[1]) == 0 && (atoi (argv[2]) == 0 || atoi(argv[2]) == 1)) {
124
for (i = 0; i < num_udis; i++) {
125
if (strcmp (udis[i], udi) == 0)
128
iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
130
path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
132
if ((fd = fopen (path, "w")) == NULL) {
136
fputc (argv[2][0], fd);
140
libhal_free_string (iface);
74
147
libhal_free_string (parent);
76
if(argc==2 && strcmp("getrfkill",argv[1])==0) {
78
for (i = 0; i < num_udis; i++) {
80
if(strcmp (udis[i], udi) == 0) continue;
81
iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
82
path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
83
if((fd=fopen (path, "r")) == NULL) return -1;
84
kill_status = fgetc (fd);
99
libhal_free_string (iface);
102
libhal_free_string_array (udis);
105
if(argc == 3 && strcmp ("setrfkill", argv[1]) == 0 && (atoi (argv[2]) == 0 || atoi(argv[2]) == 1)) {
107
for (i = 0; i < num_udis; i++) {
109
if(strcmp (udis[i], udi)==0) continue;
110
iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
111
path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
112
if((fd=fopen (path, "w")) == NULL) return -1;
113
fputc (argv[2][0], fd);
116
libhal_free_string (iface);
119
libhal_free_string_array (udis);
148
libhal_free_string_array (udis);
124
149
libhal_ctx_free (hal_ctx);
126
151
if (dbus_error_is_set (&error)) {
127
fprintf (stderr, "error: %s: %s\n", error.name, error.message);
152
syslog (LOG_INFO, "error: %s: %s\n", error.name, error.message);
128
153
dbus_error_free (&error);