Changeset 531eabd for protocols/rpc
- Timestamp:
- 2015-05-04T21:56:58Z (10 years ago)
- Children:
- b1dc403
- Parents:
- f15553d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/rpc/rpc.c
rf15553d r531eabd 174 174 * I don't want to do. 175 175 * 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(). */ 178 177 } 179 178 … … 780 779 } 781 780 782 voidrpc_initmodule_sock(struct sockaddr *address, socklen_t addrlen) {781 gboolean rpc_initmodule_sock(struct sockaddr *address, socklen_t addrlen) { 783 782 int st, fd, i; 784 783 785 784 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 } 788 791 789 792 JSON_Value *rpc = rpc_init_isup(); … … 797 800 798 801 if ((st = write(fd, s, len)) != len) { 799 // LOG ERROR800 return ;802 log_message(LOGLVL_WARNING, "Error while writing to RPC server: %s", strerror(errno)); 803 return FALSE; 801 804 } 802 805 g_free(s); … … 816 819 817 820 if (st == 0) { 818 // LOG ERROR821 log_message(LOGLVL_WARNING, "Error while reading from RPC server: %s", strerror(errno)); 819 822 closesocket(fd); 820 return ;823 return FALSE; 821 824 } 822 825 … … 828 831 if (sockerr_again()) 829 832 continue; 830 // LOG ERROR833 log_message(LOGLVL_WARNING, "Error while reading from RPC server: %s", strerror(errno)); 831 834 closesocket(fd); 832 return ;835 return FALSE; 833 836 } 834 837 resplen += st; … … 840 843 JSON_Object *isup = json_object_get_object(json_object(parsed), "result"); 841 844 if (isup == NULL) { 842 // LOG ERROR843 return ;845 log_message(LOGLVL_WARNING, "Error while parsing RPC server response"); 846 return FALSE; 844 847 } 845 848 … … 903 906 904 907 register_protocol(ret); 908 909 return TRUE; 905 910 } 906 911 … … 921 926 922 927 while ((de = readdir(pdir))) { 928 if (de->d_type != DT_SOCK && de->d_type != DT_UNKNOWN) 929 continue; 930 923 931 char *fn = g_build_filename(PDIR, de->d_name, NULL); 924 932 struct sockaddr_un su; 925 933 926 934 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 927 948 su.sun_path[UNIX_PATH_MAX-1] = '\0'; 928 949 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)); 930 951 g_free(fn); 952 if (!st) 953 log_message(LOGLVL_WARNING, "Failed to register protocol %s", fn); 931 954 /* Idea: Also support textfiles containing a host:port tuple to 932 955 * connect to. Not that remote RPC'ing would be a great idea, 933 956 * but maybe some jsonrpc libs don't support Unix domain sockets. */ 934 957 } 935 } 936 958 closedir(pdir); 959 } 960
Note: See TracChangeset
for help on using the changeset viewer.