Ignore:
Timestamp:
2015-05-04T21:56:58Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
b1dc403
Parents:
f15553d
Message:

Some more logging at RPC init time.

Through the logging subsystem which still doesn't really work...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/rpc/rpc.c

    rf15553d r531eabd  
    174174                 * I don't want to do.
    175175                 * Should a module want to override a user's setting, it can
    176                  * use set_setstr(). (Though ATM setting changes are not yet
    177                  * passed to the module immediately. TODO. */
     176                 * use set_setstr(). */
    178177        }
    179178
     
    780779}
    781780
    782 void rpc_initmodule_sock(struct sockaddr *address, socklen_t addrlen) {
     781gboolean rpc_initmodule_sock(struct sockaddr *address, socklen_t addrlen) {
    783782        int st, fd, i;
    784783
    785784        fd = socket(address->sa_family, SOCK_STREAM, 0);
    786         if (fd == -1 || connect(fd, address, addrlen) == -1)
    787                 return;
     785        if (fd == -1 || connect(fd, address, addrlen) == -1) {
     786                log_message(LOGLVL_WARNING, "Failed to connect to RPC server: %s", strerror(errno));
     787                if (fd != -1)
     788                        closesocket(fd);
     789                return FALSE;
     790        }
    788791
    789792        JSON_Value *rpc = rpc_init_isup();
     
    797800
    798801        if ((st = write(fd, s, len)) != len) {
    799                 // LOG ERROR
    800                 return;
     802                log_message(LOGLVL_WARNING, "Error while writing to RPC server: %s", strerror(errno));
     803                return FALSE;
    801804        }
    802805        g_free(s);
     
    816819
    817820                if (st == 0) {
    818                         // LOG ERROR
     821                        log_message(LOGLVL_WARNING, "Error while reading from RPC server: %s", strerror(errno));
    819822                        closesocket(fd);
    820                         return;
     823                        return FALSE;
    821824                }
    822825               
     
    828831                        if (sockerr_again())
    829832                                continue;
    830                         // LOG ERROR
     833                        log_message(LOGLVL_WARNING, "Error while reading from RPC server: %s", strerror(errno));
    831834                        closesocket(fd);
    832                         return;
     835                        return FALSE;
    833836                }
    834837                resplen += st;
     
    840843        JSON_Object *isup = json_object_get_object(json_object(parsed), "result");
    841844        if (isup == NULL) {
    842                 // LOG ERROR
    843                 return;
     845                log_message(LOGLVL_WARNING, "Error while parsing RPC server response");
     846                return FALSE;
    844847        }
    845848
     
    903906       
    904907        register_protocol(ret);
     908
     909        return TRUE;
    905910}
    906911
     
    921926
    922927        while ((de = readdir(pdir))) {
     928                if (de->d_type != DT_SOCK && de->d_type != DT_UNKNOWN)
     929                        continue;
     930
    923931                char *fn = g_build_filename(PDIR, de->d_name, NULL);
    924932                struct sockaddr_un su;
    925933
    926934                strncpy(su.sun_path, fn, UNIX_PATH_MAX);
     935
     936#if 0
     937                struct stat fdata;
     938                if (stat(fn, &fdata) == -1) {
     939                        log_message(LOGLVL_WARNING, "Could not stat %s: %s", fn, strerror(errno));
     940                        g_free(fn);
     941                        continue;
     942                }
     943                /* For now just skip anything that is not a Unix domain socket. */
     944                if (!S_ISSOCK(fdata.st_mode))
     945                        continue;
     946#endif
     947
    927948                su.sun_path[UNIX_PATH_MAX-1] = '\0';
    928949                su.sun_family = AF_UNIX;
    929                 rpc_initmodule_sock((struct sockaddr*) &su, sizeof(su));
     950                gboolean st = rpc_initmodule_sock((struct sockaddr*) &su, sizeof(su));
    930951                g_free(fn);
     952                if (!st)
     953                        log_message(LOGLVL_WARNING, "Failed to register protocol %s", fn);
    931954                /* Idea: Also support textfiles containing a host:port tuple to
    932955                 * connect to. Not that remote RPC'ing would be a great idea,
    933956                 * but maybe some jsonrpc libs don't support Unix domain sockets. */
    934957        }
    935 }
    936 
     958        closedir(pdir);
     959}
     960
Note: See TracChangeset for help on using the changeset viewer.