Changeset 4011fa0 in mainline for uspace/srv/net/netstart/netstart.c


Ignore:
Timestamp:
2010-03-31T13:32:38Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
85c2a4b
Parents:
7553689
Message:

cleanup netstart, update to HelenOS coding style, run self-tests when -s argument is used

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/netstart/netstart.c

    r7553689 r4011fa0  
    2828
    2929/** @addtogroup net
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Starts the networking subsystem.
    35  *  Performs self test if configured to.
    36  *  @see configuration.h
     34 *
     35 * Start the networking subsystem.
     36 * Perform networking self-test if executed
     37 * with the -s argument.
     38 *
    3739 */
     40
     41#define NAME  "netstart"
    3842
    3943#include <async.h>
    4044#include <stdio.h>
    4145#include <task.h>
    42 
    4346#include <ipc/ipc.h>
    4447#include <ipc/services.h>
     
    4750#include <net_modules.h>
    4851#include <net_net_messages.h>
     52
    4953#include "self_test.h"
    5054
    51 /** Networking startup module name.
     55/** Start a module.
     56 *
     57 * @param[in] desc The module description
     58 * @param[in] path The module absolute path.
     59 *
     60 * @returns true on succesful spanwning
     61 * @returns false on failure
     62 *
    5263 */
    53 #define NAME    "Networking startup"
    54 
    55 /** Starts the module.
    56  *  @param[in] fname The module absolute name.
    57  *  @returns The started module task identifier.
    58  *  @returns Other error codes as defined for the task_spawn() function.
    59  */
    60 static task_id_t spawn(const char * fname){
    61         const char * argv[2];
    62         task_id_t res;
    63 
    64         argv[0] = fname;
     64static bool spawn(const char *desc, const char *path)
     65{
     66        printf("%s: Spawning %s (%s)\n", NAME, desc, path);
     67       
     68        const char *argv[2];
     69       
     70        argv[0] = path;
    6571        argv[1] = NULL;
    66         res = task_spawn(fname, argv);
    6772       
    68         return res;
     73        if (task_spawn(path, argv) == 0) {
     74                fprintf(stderr, "%s: Error spawning %s\n", NAME, path);
     75                return false;
     76        }
     77       
     78        return true;
    6979}
    7080
    71 /** Module entry point.
    72  *  @param[in] argc The number of command line parameters.
    73  *  @param[in] argv The command line parameters.
    74  *  @returns EOK on success.
    75  *  @returns EINVAL if the net module cannot be started.
    76  *  @returns Other error codes as defined for the self_test() function.
    77  *  @returns Other error codes as defined for the NET_NET_STARTUP message.
     81/** Network startup entry point.
     82 *
     83 * @param[in] argc The number of command line parameters.
     84 * @param[in] argv The command line parameters.
     85 *
     86 * @returns EOK on success.
     87 * @returns EINVAL if the net module cannot be started.
     88 * @returns Other error codes as defined for the self_test() function.
     89 * @returns Other error codes as defined for the NET_NET_STARTUP message.
     90 *
    7891 */
    79 int main(int argc, char * argv[]){
     92int main(int argc, char *argv[])
     93{
    8094        ERROR_DECLARE;
    81 
    82         int net_phone;
    83 
    84         // print the module label
    85         printf("Task %d - ", task_get_id());
    86         printf("%s\n", NAME);
    87 
    88         // run self tests
    89         ERROR_PROPAGATE(self_test());
    90 
    91         // start the networking service
    92         if(! spawn("/srv/net")){
    93                 fprintf(stderr, "Could not spawn net\n");
     95       
     96        /* Run self-tests */
     97        if ((argc > 1) && (str_cmp(argv[1], "-s") == 0))
     98                ERROR_PROPAGATE(self_test());
     99       
     100        if (!spawn("networking service", "/srv/net"))
    94101                return EINVAL;
     102       
     103        printf("%s: Initializing networking\n", NAME);
     104       
     105        int net_phone = connect_to_service(SERVICE_NETWORKING);
     106        if (ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))) {
     107                fprintf(stderr, "%s: Networking error %d\n", NAME, ERROR_CODE);
     108                return ERROR_CODE;
    95109        }
    96 
    97         // start the networking
    98         net_phone = connect_to_service(SERVICE_NETWORKING);
    99         if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){
    100                 printf("ERROR %d\n", ERROR_CODE);
    101                 return ERROR_CODE;
    102         }else{
    103                 printf("OK\n");
    104         }
    105 
     110       
    106111        return EOK;
    107112}
Note: See TracChangeset for help on using the changeset viewer.