Changes in uspace/srv/devman/main.c [3f57fb7:655cc56] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r3f57fb7 r655cc56 245 245 246 246 fibril_rwlock_write_lock(&device_tree.rwlock); 247 247 248 248 if (fun->state == FUN_ON_LINE) { 249 249 fibril_rwlock_write_unlock(&device_tree.rwlock); … … 259 259 return ENOMEM; 260 260 } 261 261 262 262 insert_dev_node(&device_tree, dev, fun); 263 263 dev_add_ref(dev); … … 272 272 /* Give one reference over to assign_driver_fibril(). */ 273 273 dev_add_ref(dev); 274 275 274 /* 276 275 * Try to find a suitable driver and assign it to the device. We do … … 289 288 } 290 289 fibril_add_ready(assign_fibril); 291 } else 290 } else { 292 291 loc_register_tree_function(fun, &device_tree); 292 } 293 293 294 294 fibril_rwlock_write_unlock(&device_tree.rwlock); … … 855 855 } 856 856 857 /** Get function driver name. */858 static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall)859 {860 devman_handle_t handle = IPC_GET_ARG1(*icall);861 862 fun_node_t *fun = find_fun_node(&device_tree, handle);863 if (fun == NULL) {864 async_answer_0(iid, ENOMEM);865 return;866 }867 868 ipc_callid_t data_callid;869 size_t data_len;870 if (!async_data_read_receive(&data_callid, &data_len)) {871 async_answer_0(iid, EINVAL);872 fun_del_ref(fun);873 return;874 }875 876 void *buffer = malloc(data_len);877 if (buffer == NULL) {878 async_answer_0(data_callid, ENOMEM);879 async_answer_0(iid, ENOMEM);880 fun_del_ref(fun);881 return;882 }883 884 fibril_rwlock_read_lock(&device_tree.rwlock);885 886 /* Check function state */887 if (fun->state == FUN_REMOVED) {888 fibril_rwlock_read_unlock(&device_tree.rwlock);889 free(buffer);890 891 async_answer_0(data_callid, ENOENT);892 async_answer_0(iid, ENOENT);893 fun_del_ref(fun);894 return;895 }896 897 /* Check whether function has a driver */898 if (fun->child == NULL || fun->child->drv == NULL) {899 fibril_rwlock_read_unlock(&device_tree.rwlock);900 free(buffer);901 902 async_answer_0(data_callid, EINVAL);903 async_answer_0(iid, EINVAL);904 fun_del_ref(fun);905 return;906 }907 908 size_t sent_length = str_size(fun->child->drv->name);909 if (sent_length > data_len) {910 sent_length = data_len;911 }912 913 async_data_read_finalize(data_callid, fun->child->drv->name,914 sent_length);915 async_answer_0(iid, EOK);916 917 fibril_rwlock_read_unlock(&device_tree.rwlock);918 fun_del_ref(fun);919 free(buffer);920 }921 857 922 858 /** Get device path. */ … … 1147 1083 devman_fun_get_name(callid, &call); 1148 1084 break; 1149 case DEVMAN_FUN_GET_DRIVER_NAME:1150 devman_fun_get_driver_name(callid, &call);1151 break;1152 1085 case DEVMAN_FUN_GET_PATH: 1153 1086 devman_fun_get_path(callid, &call); … … 1216 1149 if (dev->pfun->dev != NULL) 1217 1150 driver = dev->pfun->dev->drv; 1218 1219 1151 fwd_h = dev->pfun->handle; 1220 1152 } else if (dev->state == DEVICE_USABLE) { … … 1222 1154 driver = dev->drv; 1223 1155 assert(driver != NULL); 1224 1156 1225 1157 fwd_h = handle; 1226 1158 } … … 1249 1181 1250 1182 if (fun != NULL) { 1251 log_msg(LVL_DEBUG, 1183 log_msg(LVL_DEBUG, 1252 1184 "Forwarding request for `%s' function to driver `%s'.", 1253 1185 fun->pathname, driver->name); 1254 1186 } else { 1255 log_msg(LVL_DEBUG, 1187 log_msg(LVL_DEBUG, 1256 1188 "Forwarding request for `%s' device to driver `%s'.", 1257 1189 dev->pfun->pathname, driver->name); … … 1261 1193 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 1262 1194 async_exchange_end(exch); 1263 1195 1264 1196 cleanup: 1265 1197 if (dev != NULL) 1266 1198 dev_del_ref(dev); 1267 1268 1199 if (fun != NULL) 1269 1200 fun_del_ref(fun); … … 1368 1299 return false; 1369 1300 } 1370 1301 1371 1302 log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized."); 1372 1303 1373 1304 /* Create root device node. */ 1374 1305 if (!init_device_tree(&device_tree, &drivers_list)) { … … 1376 1307 return false; 1377 1308 } 1378 1309 1379 1310 /* 1380 * Caution: As the device manager is not a real loc 1381 * driver (it uses a completely different IPC protocol 1382 * than an ordinary loc driver), forwarding a connection 1383 * from client to the devman by location service will 1384 * not work. 1311 * !!! devman_connection ... as the device manager is not a real loc 1312 * driver (it uses a completely different ipc protocol than an ordinary 1313 * loc driver) forwarding a connection from client to the devman by 1314 * location service would not work. 1385 1315 */ 1386 loc_server_register(NAME );1316 loc_server_register(NAME, devman_connection); 1387 1317 1388 1318 return true; … … 1391 1321 int main(int argc, char *argv[]) 1392 1322 { 1393 printf("%s: HelenOS Device Manager\n", NAME); 1394 1395 int rc = log_init(NAME, LVL_WARN); 1396 if (rc != EOK) { 1397 printf("%s: Error initializing logging subsystem.\n", NAME); 1398 return rc; 1323 printf(NAME ": HelenOS Device Manager\n"); 1324 1325 if (log_init(NAME, LVL_WARN) != EOK) { 1326 printf(NAME ": Error initializing logging subsystem.\n"); 1327 return -1; 1328 } 1329 1330 if (!devman_init()) { 1331 log_msg(LVL_ERROR, "Error while initializing service."); 1332 return -1; 1399 1333 } 1400 1334 … … 1403 1337 async_set_client_data_destructor(devman_client_data_destroy); 1404 1338 async_set_client_connection(devman_connection); 1405 1406 if (!devman_init()) { 1407 log_msg(LVL_ERROR, "Error while initializing service."); 1339 1340 /* Register device manager at naming service. */ 1341 if (service_register(SERVICE_DEVMAN) != EOK) { 1342 log_msg(LVL_ERROR, "Failed registering as a service."); 1408 1343 return -1; 1409 1344 } 1410 1411 /* Register device manager at naming service. */ 1412 rc = service_register(SERVICE_DEVMAN); 1413 if (rc != EOK) { 1414 log_msg(LVL_ERROR, "Failed registering as a service."); 1415 return rc; 1416 } 1417 1418 printf("%s: Accepting connections.\n", NAME); 1345 1346 printf(NAME ": Accepting connections.\n"); 1419 1347 task_retval(0); 1420 1348 async_manager(); 1421 1349 1422 1350 /* Never reached. */ 1423 1351 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.