app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
int _send_pkt_raw(int client_fd, app_pkt_t *pkt);
int _connect_to_launchpad(int type, int id);
-void _set_sock_option(int fd, int cli);
+int _set_sock_option(int fd, int cli);
void _set_env(appinfo_t *menu_info, bundle *kb);
char **_create_argc_argv(bundle *kb, int *margc);
char *_get_libdir(const char *path);
goto error;
}
- _set_sock_option(client_fd, 1);
+ if (_set_sock_option(client_fd, 1) < 0) {
+ _E("Failed to set sock option");
+ goto error;
+ }
recv_ret = recv(client_fd, &client_pid, sizeof(client_pid),
MSG_WAITALL);
static int __real_send(int clifd, int ret)
{
+ if (clifd < 3) {
+ _E("Invalid parameter. clifd(%d)", clifd);
+ return -1;
+ }
+
if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
if (errno == EPIPE) {
_E("send failed due to EPIPE.");
*idle = iv;
}
-void _set_sock_option(int fd, int cli)
+int _set_sock_option(int fd, int cli)
{
+ struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */
int size;
int flag;
- struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */
+ int ret;
size = AUL_SOCK_MAXBUFF;
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
+ ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
+ if (ret < 0) {
+ _E("Failed to set SO_SNDBUF option on socket. errno(%d)",
+ errno);
+ return -1;
+ }
+
+ ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
+ if (ret < 0) {
+ _E("Failed to set SO_RCVBUF option on socket. errno(%d)",
+ errno);
+ return -1;
+ }
+
if (cli) {
- setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ if (ret < 0) {
+ _E("Failed to set SO_RCVTIMEO option on socket. " \
+ "errno(%d)", errno);
+ return -1;
+ }
+
flag = fcntl(fd, F_GETFD);
flag |= FD_CLOEXEC;
- fcntl(fd, F_SETFD, flag);
+ ret = fcntl(fd, F_SETFD, flag);
+ if (ret < 0) {
+ _E("Failed to manipulate fd(F_SETFD), errno(%d)",
+ errno);
+ return -1;
+ }
}
+
+ return 0;
}
static int __parse_app_path(const char *arg, char *out, int out_size)
return -1;
}
- _set_sock_option(fd, 0);
+ if (_set_sock_option(fd, 0) < 0) {
+ _E("Failed to set sock option");
+ close(fd);
+ return -1;
+ }
if (listen(fd, 128) == -1) {
_E("listen error");
return NULL;
}
- _set_sock_option(newfd, 1);
+ if (_set_sock_option(newfd, 1) < 0) {
+ _E("Failed to set sock option");
+ close(newfd);
+ return NULL;
+ }
pkt = _recv_pkt_raw(newfd);
if (pkt == NULL) {
return -1;
}
- _set_sock_option(fd, 0);
+ if (_set_sock_option(fd, 0) < 0) {
+ _E("Failed to set sock option");
+ close(fd);
+ return -1;
+ }
if (listen(fd, 128) < 0) {
_E("Failed to listen %d, errno(%d)", fd, errno);