Example #1
0
static int 
eject_media_netbsd(void *user_data) {

	_img_private_t *_obj = user_data;
	int fd, res, ret = 0;

	fd = open(_obj->gen.source_name, O_RDONLY|O_NONBLOCK);
	if (fd < 0)
		return 2;

	res = ioctl(fd, CDIOCALLOW);
	if (res < 0) {
		cdio_error("ioctl(fd, CDIOCALLOW) failed: %s\n",
			   strerror(errno));
		/* go on... */
	}
	res = ioctl(fd, CDIOCEJECT);
	if (res < 0) {
		cdio_error("ioctl(CDIOCEJECT) failed: %s\n",
			   strerror(errno));
		ret = 1;
	}

	close(fd);
	return ret;
}
Example #2
0
int royparse_start(logerr_t* a_logerr)
{
    logerr = a_logerr;

    if (opt_q) {
        pcap  = pcap_open_dead(DLT_RAW, 65535);
        q_out = pcap_dump_open(pcap, opt_q);
        if (q_out == 0) {
            logerr("%s: %s\n", opt_q, strerror(errno));
            exit(1);
        }
    }
    if (opt_r) {
        r_out = fopen(opt_r, "w");
        if (r_out == 0) {
            logerr("%s: %s\n", opt_r, strerror(errno));
            exit(1);
        }
    } else {
        r_out = stdout;
    }
    setbuf(r_out, 0);

    return 0;
}
Example #3
0
int
get_client_socket()
{
	int sock_fd, err;
	struct sockaddr_in addr;

	memset(&addr, 0, sizeof (addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	addr.sin_port = htons(DAEMON_PORT);

	sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
	if (!sock_fd) {
		printw("ui socket error: %s\n", strerror(errno));
		refresh();
	}

	for (;;) {
		err = connect(sock_fd, (struct sockaddr *)&addr, sizeof (addr));
		if (err == 0) {
			return (sock_fd);
		}

		printw("ui connect error: %s\n", strerror(errno));
		refresh();
		sleep(1);
	}
}
Example #4
0
int EventHub::read_notify(int nfd)
{
#ifdef HAVE_INOTIFY
    int res;
    char devname[PATH_MAX];
    char *filename;
    char event_buf[512];
    int event_size;
    int event_pos = 0;
    struct inotify_event *event;

    LOGV("EventHub::read_notify nfd: %d\n", nfd);
    res = read(nfd, event_buf, sizeof(event_buf));
    if(res < (int)sizeof(*event)) {
        if(errno == EINTR)
            return 0;
        LOGW("could not get event, %s\n", strerror(errno));
        return 1;
    }
    //printf("got %d bytes of event information\n", res);

    strcpy(devname, device_path);
    filename = devname + strlen(devname);
    *filename++ = '/';

    while(res >= (int)sizeof(*event)) {
        event = (struct inotify_event *)(event_buf + event_pos);
        //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
        if(event->len) {
            strcpy(filename, event->name);
#ifdef HAVE_TSLIB
            if (!strcmp(filename, "pointercal")) {
                if (mTS->fd)
                    ts_reload(mTS);
                inotify_rm_watch(mFDs[0].fd, res);
                res = inotify_add_watch(mFDs[0].fd, pointercal_path, IN_MODIFY);
                if(res < 0) {
                    LOGE("could not add watch for %s, %s\n", pointercal_path, strerror(errno));
                }
            } else {
#else
            {
#endif
                if(event->mask & IN_CREATE) {
                    open_device(devname);
                }
                else {
                    close_device(devname);
                }
            }
#ifdef HAVE_TSLIB
        } else {
              if (mTS->fd)
                  ts_reload(mTS);
#endif
        }
        event_size = sizeof(*event) + event->len;
        res -= event_size;
        event_pos += event_size;
    }
Example #5
0
static RETSIGTYPE sig_alarm(int signo) {
  struct sigaction act;

  act.sa_handler = sig_alarm;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;

#ifdef SA_INTERRUPT
  act.sa_flags |= SA_INTERRUPT;
#endif

  /* Install this handler for SIGALRM. */
  if (sigaction(SIGALRM, &act, NULL) < 0) {
    pr_log_pri(PR_LOG_WARNING,
      "unable to install SIGALRM handler via sigaction(2): %s",
      strerror(errno));
  }

#ifdef HAVE_SIGINTERRUPT
  if (siginterrupt(SIGALRM, 1) < 0) {
    pr_log_pri(PR_LOG_WARNING,
      "unable to allow SIGALRM to interrupt system calls: %s", strerror(errno));
  }
#endif

  recvd_signal_flags |= RECEIVED_SIG_ALRM;
  nalarms++;

  /* Reset the alarm */
  _total_time += _current_timeout;
  if (_current_timeout) {
    _alarmed_time = time(NULL);
    alarm(_current_timeout);
  }
}
Example #6
0
int
setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
	int ret = 0, saved_errno;

	if (rgid != sgid) {
		errno = ENOSYS;
		return -1;
	}
#if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID)
	if (setregid(rgid, egid) < 0) {
		saved_errno = errno;
		error("setregid %u: %.100s", rgid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
#else
	if (setegid(egid) < 0) {
		saved_errno = errno;
		error("setegid %u: %.100s", (u_int)egid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
	if (setgid(rgid) < 0) {
		saved_errno = errno;
		error("setgid %u: %.100s", rgid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
#endif
	return ret;
}
void EmulatedCameraHotplugThread::requestExit() {
    Mutex::Autolock al(mMutex);

    ALOGV("%s: Requesting thread exit", __FUNCTION__);
    mRunning = false;

    bool rmWatchFailed = false;
    Vector<SubscriberInfo>::iterator it;
    for (it = mSubscribers.begin(); it != mSubscribers.end(); ++it) {

        if (inotify_rm_watch(mInotifyFd, it->WatchID) == -1) {

            ALOGE("%s: Could not remove watch for camID '%d',"
                  " error: '%s' (%d)",
                 __FUNCTION__, it->CameraID, strerror(errno),
                 errno);

            rmWatchFailed = true ;
        } else {
            ALOGV("%s: Removed watch for camID '%d'",
                __FUNCTION__, it->CameraID);
        }
    }

    if (rmWatchFailed) { // unlikely
        // Give the thread a fighting chance to error out on the next
        // read
        if (close(mInotifyFd) == -1) {
            ALOGE("%s: close failure error: '%s' (%d)",
                 __FUNCTION__, strerror(errno), errno);
        }
    }

    ALOGV("%s: Request exit complete.", __FUNCTION__);
}
Example #8
0
/* make the devices for a volume */
void
make_vol_dev(int volno, int recurse)
{
    dev_t voldev;
    char filename[PATH_MAX];				    /* for forming file names */
    int plexno;

    get_volume_info(&vol, volno);
    if (vol.state != volume_unallocated) {		    /* we could have holes in our lists */
	voldev = VINUMDEV(volno, 0, 0, VINUM_VOLUME_TYPE);  /* create a device number */

	/* Create /dev/vinum/<myvol> */
	sprintf(filename, VINUM_DIR "/%s", vol.name);
	if (mknod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, voldev) < 0)
	    fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));

	/* Create /dev/vinum/vol/<myvol> */
	sprintf(filename, VINUM_DIR "/vol/%s", vol.name);
	if (mknod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, voldev) < 0)
	    fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));

	if (vol.plexes > 0) {
	    /* Create /dev/vinum/vol/<myvol>.plex/ */
	    sprintf(filename, VINUM_DIR "/vol/%s.plex", vol.name);
	    if (mkdir(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IXOTH) < 0)
		fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));
	}
	if (recurse)
	    for (plexno = 0; plexno < vol.plexes; plexno++)
		make_plex_dev(plex.plexno, recurse);
    }
}
Example #9
0
struct watchman_connection *
watchman_sock_connect(struct watchman_error *error, const char *sockname)
{
    struct sockaddr_un addr = { };

    int fd;
    if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
        watchman_err(error, "Socket error %s", strerror(errno));
        return NULL;
    }

    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, sockname, sizeof(addr.sun_path) - 1);

    if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
        close(fd);
        watchman_err(error, "Connect error %s", strerror(errno));
        return NULL;
    }

    FILE *sockfp = fdopen(fd, "r+");
    if (!sockfp) {
        close(fd);
        watchman_err(error,
                     "Failed to connect to watchman socket %s: %s.",
                     sockname, strerror(errno));
        return NULL;
    }
    setlinebuf(sockfp);

    struct watchman_connection *conn = malloc(sizeof(*conn));
    conn->fp = sockfp;
    return conn;
}
Example #10
0
struct json_object* json_object_from_file(const char *filename)
{
    struct printbuf *pb;
    struct json_object *obj;
    char buf[JSON_FILE_BUF_SIZE];
    int fd, ret;

    if((fd = open(filename, O_RDONLY)) < 0) {
        MC_ERROR("json_object_from_file: error reading file %s: %s\n",
                 filename, strerror(errno));
        return (struct json_object*)error_ptr(-1);
    }
    if(!(pb = printbuf_new())) {
        MC_ERROR("json_object_from_file: printbuf_new failed\n");
        return (struct json_object*)error_ptr(-1);
    }
    while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
        printbuf_memappend(pb, buf, ret);
    }
    close(fd);
    if(ret < 0) {
        MC_ABORT("json_object_from_file: error reading file %s: %s\n",
                 filename, strerror(errno));
        printbuf_free(pb);
        return (struct json_object*)error_ptr(-1);
    }
    obj = json_tokener_parse(pb->buf);
    printbuf_free(pb);
    return obj;
}
Example #11
0
/*
 * create_timer_wheel()
 *
 * Creates the timer wheel structure and starts
 * the rotation timer.
 */
timer_t create_wheel_timer(void)
{
    timer_t tid;
    struct sigevent sev;
    struct itimerspec timerspec;

    sev.sigev_notify = SIGEV_SIGNAL;
    sev.sigev_signo = SIGRTMIN;
    sev.sigev_value.sival_ptr = &tid;
    if (timer_create(CLOCK_REALTIME, &sev, &tid) == -1)
    {
        syslog(LOG_INFO, "timer_create(): %s", strerror(errno));
        return (timer_t)0;
    }

    timerspec.it_value.tv_nsec = 0;
    timerspec.it_value.tv_sec = TimerTickInterval;
    timerspec.it_interval.tv_nsec = 0;
    timerspec.it_interval.tv_sec = TimerTickInterval;
    syslog(LOG_ERR, "Master wheel tick timer %d set for %d seconds",
           tid, timerspec.it_value.tv_sec);

    if (timer_settime(tid, 0, &timerspec, NULL) == -1) {
        syslog(LOG_INFO, "timer start failed for %d %s",
               tid, strerror(errno));
        return (timer_t)0;
    }
    return(tid);
}
Example #12
0
File: 11.3.cpp Project: imafish/tmp
int main()
{
    int err;
    pthread_t tid1, tid2;
    struct foo *fp;

    err = pthread_create(&tid1, NULL, thr_fn1, NULL);
    if (err != 0) {
        err_quit("can't create therad 1: %s\n", strerror(err));
    }
    err = pthread_join(tid1, (void **)&fp);
    if (err != 0) {
        err_quit("can't join with thread 1: %s\n", strerror(err));
    }
    sleep(1);
    printf("parent starting second thread\n");
    err = pthread_create(&tid2, NULL, thr_fn2, NULL);
    if (err != 0) {
        err_quit("cannpt create thread 2: %s\n", strerror(err));
    }
    err = pthread_join(tid2, NULL);
    if (err != 0) {
        err_quit("can't join with thread 2: %s\n", strerror(err));
    }

    printfoo("parent:\n", fp);

    return 0;
}
Example #13
0
void PIRFlashLED::openFlashDevice()
{
  // Not sure why "O_RDWR", but it seems to be necessary:
  fileDescriptor = open(PATH_TO_FLASH_DEVICE, O_RDWR | O_NONBLOCK, 0);

  if (fileDescriptor == -1)
  {
    std::stringstream ss;
    ss << "Failed to connect to " << PATH_TO_FLASH_DEVICE << "\n";
    ss << "Error is " << strerror(errno) << "\n";
    throw PIRException(ss.str());
  }

  // Find out the intensity values for the LED:

  struct v4l2_queryctrl qctrl;

  // Retrieve intensity values for strobe usage:
  qctrl.id = V4L2_CID_FLASH_INTENSITY;

  if (ioctl(fileDescriptor, VIDIOC_QUERYCTRL, &qctrl) == -1)
  {
    std::stringstream ss;
    ss << "Failed to retrieve flash LED intensity values.\n";
    ss << "Error is " << strerror(errno) << "\n";
    throw PIRException(ss.str());
  }

  minFlash = qctrl.minimum;
  maxFlash = qctrl.maximum;

  // Retrieve timeout values for strobe usage:
  qctrl.id = V4L2_CID_FLASH_TIMEOUT;

  if (ioctl(fileDescriptor, VIDIOC_QUERYCTRL, &qctrl) == -1)
  {
    std::stringstream ss;
    ss << "Failed to retrieve flash timeout values.\n";
    ss << "Error is " << strerror(errno) << "\n";
    throw PIRException(ss.str());
  }

  maxTime = qctrl.maximum;

/*
  // Retrieve intensity values for sustained usage:
  qctrl.id = V4L2_CID_TORCH_INTENSITY;

  if (ioctl(fileDescriptor, VIDIOC_QUERYCTRL, &qctrl) == -1)
  {
    std::stringstream ss;
    ss << "Failed to retrieve torch LED intensity values.\n";
    ss << "Error is " << strerror(errno) << "\n";
    throw PIRException(ss.str());
  }

  minTorch = qctrl.minimum;
  maxTorch = qctrl.maximum;
*/
}
Example #14
0
int port_open_port(int work_sockfd, int port, int* listenfd) {
	struct sockaddr_in addr;
	
	if ((*listenfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
		printf("Error socket(): %s(%d)\n", strerror(errno), errno);
		return 1;
	}
	
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = port;
	addr.sin_addr.s_addr = htonl(INADDR_ANY);
	
	if (bind(*listenfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
		printf("Error bind(): %s(%d)\n", strerror(errno), errno);
		close(*listenfd);
		return 1;	
	}
	
	if (listen(*listenfd, 10) == -1) {
		printf("Error listen(): %s(%d)\n", strerror(errno), errno);
		close(*listenfd);
		return 1;	
	}
	
	return 0;
}
Example #15
0
int
open_udp_datagram_socket(int afi)
{
    struct protoent *proto = NULL;
    int sock = ERR_SOCKET;
    int tr = 1;
    int protonum = 0;

#ifdef ANDROID
    protonum = IPPROTO_UDP;
#else
    if ((proto = getprotobyname("UDP")) == NULL) {
        OOR_LOG(LERR, "open_udp_datagram_socket: getprotobyname: %s", strerror(errno));
        return(ERR_SOCKET);
    }
    protonum = proto->p_proto;
#endif

    if ((sock = socket(afi, SOCK_DGRAM, protonum)) < 0) {
        OOR_LOG(LERR, "open_udp_datagram_socket: socket: %s", strerror(errno));
        return (ERR_SOCKET);
    }
    OOR_LOG(LDBG_3, "open_udp_datagram_socket: Created socket %d associated to %s addresses\n",
            sock, (afi == AF_INET) ? "IPv4":"IPv6");

    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &tr, sizeof(int)) == -1) {
        OOR_LOG(LWRN, "open_udp_datagram_socket: setsockopt SO_REUSEADDR: %s",
                strerror(errno));

        return (ERR_SOCKET);
    }

    return sock;
}
Example #16
0
File: find.c Project: mbryk/OS
void directory(char *direct){
	DIR *dirp;
	struct dirent *de;
	int i;

	if((dirp = opendir(direct))==NULL){
		fprintf(stderr,"Error opening directory %s: %s\n", direct, strerror(errno));
		exit(-1);
	}
	while((de = readdir(dirp))!=NULL){
		char *pathname = malloc(strlen(direct)+strlen(de->d_name)+2);
		if(pathname==NULL){
			fprintf(stderr, "Error Allocating Memory. Please try again. %s\n", strerror(errno));
			exit(-1);
		}
		strcpy(pathname, direct);
		strcat(pathname, "/");
		strcat(pathname, de->d_name);
		
		if(!(i=check_file(pathname, de->d_name))){
			print_info(pathname);
		}			
		/* If device number was different or it is ".","..", stop stepping through the directory */
		if(de->d_type==DT_DIR && i!=2)
			directory(pathname);
	}

	if(closedir(dirp)<0){
		fprintf(stderr, "Error Closing Directory %s: %s\n", direct, strerror(errno));
		exit(-1);
	}
}
Example #17
0
void install_sigchld_signal_handle() {
    int pipes[2];
    struct sigaction action;
    sigset_t empty_mask;
    
    sigemptyset(&empty_mask);

    /* Fill action with handle_sigchld function */
    action.sa_sigaction = &handle_sigchld;
    action.sa_flags = SA_SIGINFO|SA_RESTART;
    action.sa_mask = empty_mask;
    
    singularity_message(DEBUG, "Assigning SIGCHLD sigaction()\n");
    if ( -1 == sigaction(SIGCHLD, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGCHLD signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    
    /* Open pipes for handle_sigchld() to write to */
    singularity_message(DEBUG, "Creating sigchld signal pipes\n");
    if ( -1 == pipe2(pipes, O_CLOEXEC) ) {
        singularity_message(ERROR, "Failed to create communication pipes: %s\n", strerror(errno));
        ABORT(255);
    }
    sigchld_signal_rpipe = pipes[0];
    sigchld_signal_wpipe = pipes[1];
}
Example #18
0
/// check free space 
void check_free_space(int* ret, unsigned long long size) {

	unsigned long long dest_size;
	struct statvfs stvfs;
	struct stat stat;
	int debug = 1;

	if (fstatvfs(*ret, &stvfs) == -1) {
		printf("WARNING: Unknown free space on the destination: %s\n",
			strerror(errno));
		return;
	}

	/* if file is a FIFO there is no point in checking the size */
	if (!fstat(*ret, &stat)) {
		if (S_ISFIFO(stat.st_mode))
			return;
	} else {
		printf("WARNING: Couldn't get file info because of the following error: %s\n",
			strerror(errno));
	}

	dest_size = (unsigned long long)stvfs.f_frsize * stvfs.f_bfree;
	if (!dest_size)
		dest_size = (unsigned long long)stvfs.f_bsize * stvfs.f_bfree;

	if (dest_size < size)
		log_mesg(0, 1, 1, debug, "Destination doesn't have enough free space: %llu MB < %llu MB\n", print_size(dest_size, MBYTE), print_size(size, MBYTE));
}
Example #19
0
int
setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
	int ret = 0, saved_errno;

	if (ruid != suid) {
		errno = ENOSYS;
		return -1;
	}
#if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
	if (setreuid(ruid, euid) < 0) {
		saved_errno = errno;
		error("setreuid %u: %.100s", ruid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
#else

# ifndef SETEUID_BREAKS_SETUID
	if (seteuid(euid) < 0) {
		saved_errno = errno;
		error("seteuid %u: %.100s", euid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
# endif
	if (setuid(ruid) < 0) {
		saved_errno = errno;
		error("setuid %u: %.100s", ruid, strerror(errno));
		errno = saved_errno;
		ret = -1;
	}
#endif
	return ret;
}
Example #20
0
/// the io function, reference from ntfsprogs(ntfsclone).
int io_all(int *fd, char *buf, unsigned long long count, int do_write, cmd_opt* opt) {
	long long int i;
	int debug = opt->debug;
	unsigned long long size = count;

	// for sync I/O buffer, when use stdin or pipe.
	while (count > 0) {
		if (do_write)
			i = write(*fd, buf, count);
		else
			i = read(*fd, buf, count);

		if (i < 0) {
			log_mesg(1, 0, 1, debug, "%s: errno = %i(%s)\n",__func__, errno, strerror(errno));
			if (errno != EAGAIN && errno != EINTR) {
				return -1;
			}
		} else if (i == 0) {
			log_mesg(1, 0, 1, debug, "%s: nothing to read. errno = %i(%s)\n",__func__, errno, strerror(errno));
			return 0;
		} else {
			count -= i;
			buf = i + (char *) buf;
			log_mesg(2, 0, 0, debug, "%s: read %lli, %llu left.\n",__func__, i, count);
		}
	}
	return size;
}
void node_persistent_cache::writeout_dirty_nodes()
{
    for (int i = 0; i < READ_NODE_CACHE_SIZE; i++)
    {
        if (readNodeBlockCache[i].dirty)
        {
            if (lseek64(node_cache_fd,
                    (readNodeBlockCache[i].block_offset
                            << READ_NODE_BLOCK_SHIFT)
                            * sizeof(ramNode)
                            + sizeof(persistentCacheHeader),
                        SEEK_SET) < 0) {
                fprintf(stderr, "Failed to seek to correct position in node cache: %s\n",
                        strerror(errno));
                util::exit_nicely();
            };
            if (write(node_cache_fd, readNodeBlockCache[i].nodes,
                    READ_NODE_BLOCK_SIZE * sizeof(ramNode))
                    < ssize_t(READ_NODE_BLOCK_SIZE * sizeof(ramNode)))
            {
                fprintf(stderr, "Failed to write out node cache: %s\n",
                        strerror(errno));
                util::exit_nicely();
            }
        }
        readNodeBlockCache[i].dirty = 0;
    }
}
Example #22
0
static int flash_exec(struct ast_channel *chan, void *data)
{
	int res = -1;
	int x;
	struct localuser *u;
	struct zt_params ztp;
	LOCAL_USER_ADD(u);
	if (!strcasecmp(chan->type, "Zap")) {
		memset(&ztp, 0, sizeof(ztp));
		res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
		if (!res) {
			if (ztp.sigtype & __ZT_SIG_FXS) {
				x = ZT_FLASH;
				res = ioctl(chan->fds[0], ZT_HOOK, &x);
				if (!res || (errno == EINPROGRESS)) {
					if (res) {
						/* Wait for the event to finish */
						zt_wait_event(chan->fds[0]);
					}
					res = ast_safe_sleep(chan, 1000);
					if (option_verbose > 2)
						ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
				} else
					ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
			} else
				ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
		} else
			ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
	} else
		ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
	LOCAL_USER_REMOVE(u);
	return res;
}
Example #23
0
void binder_loop(struct binder_state* bs, binder_handler func) {
  int res;
  struct binder_write_read bwr;
  uint32_t readbuf[32];

  bwr.write_size = 0;
  bwr.write_consumed = 0;
  bwr.write_buffer = 0;

  readbuf[0] = BC_ENTER_LOOPER;
  binder_write(bs, readbuf, sizeof(uint32_t));

  for (;;) {
    bwr.read_size = sizeof(readbuf);
    bwr.read_consumed = 0;
    bwr.read_buffer = (uintptr_t) readbuf;

    res = ioctl(bs->fd, BINDER_WRITE_READ, &bwr);
    if (res < 0) {
      fprintf(stderr, "binder_loop: ioctl failed (%s)\n", strerror(errno));
      break;
    }

    res = binder_parse(bs, 0, (uintptr_t) readbuf, bwr.read_consumed, func);
    if (res == 0) {
      fprintf(stderr, "binder_loop: unexpected reply?!\n");
      break;
    }
    if (res < 0) {
      fprintf(stderr, "binder_loop: io error %d %s\n", res, strerror(errno));
      break;
    }
  }
}
Example #24
0
File: msg.c Project: CESNET/torque
/*
 * Tries to connect site with ip 'site'. If the connection is already
 * established then is_open is set to '1'. New message management thread
 * is started.
 */
static int connect_site(char *site, int *is_open,
        pthread_t * hm_thrp) {
    int eid, ret;
    int s;
    msg_mng_loop_args *mma;
    if ((s = get_connected_socket(site, PORT, is_open, &eid)) < 0)
        return (CON_FAILED);

    if (*is_open) {
        return (0);
    }
    if ((mma = calloc(sizeof (msg_mng_loop_args), 1)) == NULL) {
        pax_log(LOG_ERR,"connect site: msg_mng_loop struct allocation: %s\n", strerror(errno));
        ret = errno;
        goto err;
    }


    mma->fd = s;
    mma->eid = eid;
    mma->m_index = ip2index(site);
    if ((ret = pthread_create(hm_thrp, NULL,
            msg_mng_loop, (void *) mma)) != 0) {
        pax_log(LOG_ERR,"connect site:msg_mng_loop creation %s\n", strerror(errno));
        goto err1;
    }
    return (0);

err1:
    free(mma);
err:
    return (ret);
}
Example #25
0
int
restore(pink_easy_process_t *current)
{
	pid_t pid = pink_easy_process_get_pid(current);
	pink_bitness_t bit = pink_easy_process_get_bitness(current);
	proc_data_t *data = pink_easy_process_get_userdata(current);

	/* Restore system call number */
	if (!pink_util_set_syscall(pid, bit, data->sno)) {
		if (errno == ESRCH)
			return PINK_EASY_CFLAG_DROP;
		warning("pink_util_set_syscall(%lu, %s, %s): errno:%d (%s)",
				(unsigned long)pid, pink_bitness_name(bit),
				pink_name_syscall(data->sno, bit),
				errno, strerror(errno));
	}

	/* Return the saved return value */
	if (!pink_util_set_return(pid, data->ret)) {
		if (errno == ESRCH)
			return PINK_EASY_CFLAG_DROP;
		warning("pink_util_set_return(%lu, %s, %s): errno:%d (%s)",
				(unsigned long)pid, pink_bitness_name(bit),
				pink_name_syscall(data->sno, bit),
				errno, strerror(errno));
	}

	return 0;
}
Example #26
0
/*
 * Server subtask
 */
static rtems_task workerTask(rtems_task_argument arg)
{
    int s = arg;
    char msg[80];
    char reply[100];
    int i;

    for (;;) {
        if ((i = read(s, msg, sizeof msg)) < 0) {
            printf("Server couldn't read message from client: %s\n", strerror(errno));
            break;
        }
        if (i == 0)
            break;
        rtems_task_wake_after(20); /* Simulate some processing delay */
        i = sprintf(reply, "Server received %d (%s)", i, msg);
        if ((i = write(s, reply, i+1)) < 0) {
            printf("Server couldn't write message to client: %s\n", strerror(errno));
            break;
        }
    }
    if (close(s) < 0)
        printf("Can't close worker task socket: %s\n", strerror(errno));
    printf("Worker task terminating.\n");
    rtems_task_delete(RTEMS_SELF);
}
Example #27
0
bool util_try_lockf(const char * lockfile , mode_t mode , int * __fd) {
  int status;
  int lock_fd;
  lock_fd = open(lockfile , O_WRONLY + O_CREAT , mode);
  if (lock_fd == -1)
    util_abort("%s: failed to open lockfile:%s %d/%s\n",__func__ , lockfile,errno , strerror(errno));

  fchmod(lock_fd , mode);
  status = lockf(lock_fd , F_TLOCK , 0);
  if (status == 0) {
    /* We got the lock for exclusive access - all is hunkadory.*/
    *__fd = lock_fd;
    return true;
  } else {
    if (errno == EACCES || errno == EAGAIN) {
      close(lock_fd);
      *__fd = -1;

      return false;
    } else {
      util_abort("%s: lockf() system call failed:%d/%s \n",__func__ , errno , strerror(errno));
      return false; /* Compiler shut up. */
    }
  }
}
Example #28
0
/*
 * Server Task
 */
static rtems_task serverTask(rtems_task_argument arg)
{
    int s, s1;
    socklen_t addrlen;
    struct sockaddr_in myAddr, farAddr;
    rtems_task_priority myPriority;

    printf("Create socket.\n");
    s = socket(AF_INET, SOCK_STREAM, 0);
    if (s < 0)
        rtems_panic("Can't create socket: %s\n", strerror(errno));
    memset(&myAddr, 0, sizeof myAddr);
    myAddr.sin_family = AF_INET;
    myAddr.sin_port = htons(1234);
    myAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    printf("Bind socket.\n");
    if (bind(s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
        rtems_panic("Can't bind socket: %s\n", strerror(errno));
    if (listen(s, 5) < 0)
        printf("Can't listen on socket: %s\n", strerror(errno));
    rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &myPriority);
    for(;;) {
        addrlen = sizeof farAddr;
        s1 = accept(s, (struct sockaddr *)&farAddr, &addrlen);
        if (s1 < 0)
            if (errno == ENXIO)
                rtems_task_delete(RTEMS_SELF);
            else
                rtems_panic("Can't accept connection: %s", strerror(errno));
        else
            printf("ACCEPTED:%lX\n", ntohl(farAddr.sin_addr.s_addr));
        spawnTask(workerTask, myPriority, s1);
    }
}
Example #29
0
void
InsertString (stringlist_t * list, char *string)
{

  if (!list->list)
    {
      list->max_index = list->block_size;
      list->num_strings = 0;
      list->list = (char **) malloc (list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("malloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }
  list->list[list->num_strings++] = string ? strdup (string) : NULL;

  if (list->num_strings == list->max_index)
    {
      list->max_index += list->block_size;
      list->list =
	(char **) realloc (list->list, list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("realloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }

}				// End of InsertString
Example #30
0
static bool
_cdio_read_toc(_img_private_t *_obj) 
{
	int res;
	struct ioc_read_toc_entry req;

	res = ioctl(_obj->gen.fd, CDIOREADTOCHEADER, &_obj->tochdr);
	if (res < 0) {
		cdio_error("error in ioctl(CDIOREADTOCHEADER): %s\n",
			   strerror(errno));
		return false;
	}

	req.address_format = CD_MSF_FORMAT;
	req.starting_track = FIRST_TRACK_NUM;
	req.data_len = (TOTAL_TRACKS + 1) /* leadout! */
		* sizeof(struct cd_toc_entry); 
	req.data = _obj->tocent;

	res = ioctl(_obj->gen.fd, CDIOREADTOCENTRIES, &req);
	if (res < 0) {
		cdio_error("error in ioctl(CDROMREADTOCENTRIES): %s\n",
			   strerror(errno));
		return false;
	}

	_obj->toc_valid = 1;
	return true;
}