Example #1
0
void process_negprot_reply(int fd)
{ struct nbt_session_header *nbt_hdr;
 struct smb_base_header *base_hdr;
 struct negprot_reply_header *np_reply_hdr;
 char packet[1024];
 int size;
 uint16 pid_reply;

 nbt_hdr = (struct nbt_session_header *)packet;
 base_hdr = (struct smb_base_header *)(packet + sizeof (struct
nbt_session_header));
 np_reply_hdr = (struct negprot_reply_header *)(packet + (sizeof (struct
nbt_session_header) +
 sizeof (struct smb_base_header)));

 if ((size = read(fd, packet, sizeof (packet))) == -1)
 { close(fd);
 fprintf(stderr, "read() failed, reason: '%s' (code %i)\n",
strerror(errno), errno);
 exit(-errno);
 }

 // bekijk het antwoord even vluchtig.
 memcpy(&pid_reply, &base_hdr->pid, sizeof (uint16));
 memcpy(&sessionid, &np_reply_hdr->sessionid, sizeof (uint32));
 if (base_hdr->command != SMB_NEGPROT || np_reply_hdr->wordcount != 17 ||
pid_reply != pid)
 { close(fd);
 fprintf(stderr, "protocol negotiation failed\n");
 exit(-1);
 }

 printf("protocol negotiation complete\n");
}
Example #2
0
int
FindFreeTcpPort(void)
{
  int sock, port;
  struct sockaddr_in addr;

  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);

  if (!initSockets())
    return -1;

  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    rfbClientErr(": FindFreeTcpPort: socket\n");
    return 0;
  }

  for (port = TUNNEL_PORT_OFFSET + 99; port > TUNNEL_PORT_OFFSET; port--) {
    addr.sin_port = htons((unsigned short)port);
    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
      close(sock);
      return port;
    }
  }

  close(sock);
  return 0;
}
Example #3
0
int board_id_get(char *id) {
	board_id_open_device();
	int result = 0;
	int ioctl_cmd_temp = BOARD_ID_IOCTL_READ_VENDOR_DATA;

	if (!id) {
		__android_log_print(ANDROID_LOG_ERROR, "lib_rkinfo", "%s:id is null\n",
				__FUNCTION__);
		goto error;
	}

	if (0 > ioctl(sCtrlFd, ioctl_cmd_temp, id)) {
//		printf("%s:line=%d,error=%s\n", __FUNCTION__, __LINE__,
//				strerror(errno));
		__android_log_print(ANDROID_LOG_ERROR, "lib_rkinfo",
				"%s:line=%d,error=%s", __FUNCTION__, __LINE__, strerror(errno));
		result = -1;
		goto error;
	}
	close(sCtrlFd);
	return result;

	error:
	close(sCtrlFd);
	strcpy(id, "123456789");
	return result;
}
void append_redirect(char input[]){
		//printf("!1\n");
                int fd;
                char *tok;
                char path[256];
                char command[256];

                memset(path,0,256);
                memset(command,0,256);


                tok=strtok(input,">");
		//printf("!2%s\n",tok);
                strcpy(command,tok);
		
                tok = strtok(NULL,">");
		//printf("!3%s\n",tok);
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
		//printf("!4%s\n",path);
                fd = open(path,O_RDWR|O_CREAT|O_APPEND);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);

          


}
Example #5
0
int main(int argc, char **argv)
{
    int id = geteuid();
    if (id != 0)
    {
        printf("You must run this program as root\n");
        return -1;
    }
    if (argc != 2)
    {
        printf("You must specify the rpm for the fan, value must be between 2000 and 6200\n");
        return -1;
    }
    int parameter = atoi(argv[1]);
    
    if (parameter >= 2000 && parameter <= 6200)
    {
        int file;
        file = open("/sys/devices/platform/applesmc.768/fan1_manual", O_WRONLY | O_CREAT);
        write(file, "1", (ssize_t)1);
        close(file);
        
        file = open("/sys/devices/platform/applesmc.768/fan1_output", O_WRONLY | O_CREAT);
        write(file, argv[1], (ssize_t)4);
        close(file);
        printf("Fan RPM changed to %s\n", argv[1]);
    }
    else
    {
        printf("Value must be between 2000 and 6200\n");
    }
    return 0;
}
Example #6
0
int
carp_demote_get(char *group)
{
	int			s;
	struct ifgroupreq	ifgr;

	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		log_warn("%s: socket", __func__);
		return (-1);
	}

	bzero(&ifgr, sizeof(ifgr));
	if (strlcpy(ifgr.ifgr_name, group, sizeof(ifgr.ifgr_name)) >=
	    sizeof(ifgr.ifgr_name)) {
		log_warn("%s: invalid group", __func__);
		return (-1);
	}

	if (ioctl(s, SIOCGIFGATTR, (caddr_t)&ifgr) == -1) {
		if (errno == ENOENT)
			log_warnx("%s: group \"%s\" does not exist",
			    __func__, group);
		else
			log_warn("%s: ioctl", __func__);
		close(s);
		return (-1);
	}

	close(s);
	return ((int)ifgr.ifgr_attrib.ifg_carp_demoted);
}
Example #7
0
bool
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid)
{
    char *line;
    bool rval = false;
    debug_decl(get_pty, SUDO_DEBUG_PTY)

    *master = posix_openpt(O_RDWR|O_NOCTTY);
    if (*master != -1) {
	(void) grantpt(*master); /* may fork */
	if (unlockpt(*master) != 0) {
	    close(*master);
	    goto done;
	}
	line = ptsname(*master);
	if (line == NULL) {
	    close(*master);
	    goto done;
	}
	*slave = open(line, O_RDWR|O_NOCTTY, 0);
	if (*slave == -1) {
	    close(*master);
	    goto done;
	}
# if defined(I_PUSH) && !defined(_AIX)
	ioctl(*slave, I_PUSH, "ptem");	/* pseudo tty emulation module */
	ioctl(*slave, I_PUSH, "ldterm");	/* line discipline module */
# endif
	(void) chown(line, ttyuid, -1);
	strlcpy(name, line, namesz);
	rval = true;
    }
done:
    debug_return_bool(rval);
}
Example #8
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 #9
0
FILE *
Popen(char *cmd, const char *mode)
{
	int p[2];
	int myside, hisside, fd0, fd1;
	int pid;
	sigset_t nset;
	FILE *fp;

	if (pipe(p) < 0)
		return (NULL);
	(void)fcntl(p[READ], F_SETFD, 1);
	(void)fcntl(p[WRITE], F_SETFD, 1);
	if (*mode == 'r') {
		myside = p[READ];
		fd0 = -1;
		hisside = fd1 = p[WRITE];
	} else {
		myside = p[WRITE];
		hisside = fd0 = p[READ];
		fd1 = -1;
	}
	(void)sigemptyset(&nset);
	if ((pid = start_command(cmd, &nset, fd0, fd1, NULL, NULL, NULL)) < 0) {
		(void)close(p[READ]);
		(void)close(p[WRITE]);
		return (NULL);
	}
	(void)close(hisside);
	if ((fp = fdopen(myside, mode)) != NULL)
		register_file(fp, 1, pid);
	return (fp);
}
Example #10
0
sensors_poll_context_t::~sensors_poll_context_t() {
    for (int i=0 ; i<numSensorDrivers ; i++) {
        delete mSensors[i];
    }
    close(mPollFds[wake].fd);
    close(mWritePipeFd);
}
Example #11
0
void swAio_handler_write_file(swAio_event *event)
{
    int ret = -1;
    int fd = open(event->req, event->flags, 0644);
    if (fd < 0)
    {
        swSysWarn("open(%s, %d) failed", (char * )event->req, event->flags);
        event->ret = ret;
        event->error = errno;
        return;
    }
    if (event->lock && flock(fd, LOCK_EX) < 0)
    {
        swSysWarn("flock(%d, LOCK_EX) failed", event->fd);
        event->ret = ret;
        event->error = errno;
        close(fd);
        return;
    }
    size_t written = swoole_sync_writefile(fd, event->buf, event->nbytes);
    if (event->flags & SW_AIO_WRITE_FSYNC)
    {
        if (fsync(fd) < 0)
        {
            swSysWarn("fsync(%d) failed", event->fd);
        }
    }
    if (event->lock && flock(fd, LOCK_UN) < 0)
    {
        swSysWarn("flock(%d, LOCK_UN) failed", event->fd);
    }
    close(fd);
    event->ret = written;
    event->error = 0;
}
Example #12
0
int
interface_link_status(char *ifname)
{
	struct ifmediareq ifmr;
	int sock;

	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
		error("Can't create socket");

	memset(&ifmr, 0, sizeof(ifmr));
	strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
	if (ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmr) == -1) {
		/* EINVAL -> link state unknown. treat as active */
		if (errno != EINVAL)
			syslog(LOG_DEBUG, "ioctl(SIOCGIFMEDIA) on %s: %m",
			    ifname);
		close(sock);
		return (1);
	}
	close(sock);

	if (ifmr.ifm_status & IFM_AVALID) {
		switch (ifmr.ifm_active & IFM_NMASK) {
		case IFM_ETHER:
		case IFM_IEEE80211:
			if (ifmr.ifm_status & IFM_ACTIVE)
				return (1);
			else
				return (0);
		}
	}
	return (1);
}
Example #13
0
void process_sesssetupx_reply(int fd)
{ struct nbt_session_header *nbt_hdr;
 struct smb_base_header *base_hdr;
 struct sesssetupx_reply_header *sx_hdr;
 char packet[1024];
 int size, len;

// lees het packet
 if ((size = read(fd, packet, sizeof (packet))) == -1)
 { close(fd);
 fprintf(stderr, "read() failed, reason: '%s' (code %i)\n",
strerror(errno), errno);
 exit(-errno);
 }

 nbt_hdr = (struct nbt_session_header *)packet;
 base_hdr = (struct smb_base_header *)(packet + sizeof (struct
nbt_session_header));
 sx_hdr = (struct sesssetupx_reply_header *)(packet + sizeof (struct
nbt_session_header) + sizeof (struct smb_base_header));

 memcpy(&len, &nbt_hdr->len, sizeof (uint16));
 memcpy(&uid, &base_hdr->uid, sizeof (uint16));

// even een vluchtige check
 if (sx_hdr->xcommand != 0xff && sx_hdr->wordcount != 3)
 { close(fd);
 fprintf(stderr, "session setup failed\n");
 exit(-1);
 }

 printf("session setup complete, got assigned uid %i\n", uid);
}
Example #14
0
void sesssetupx_request(int fd)
{ uint8 data[] = "\x12\x0\x0\x0\x55\x6e\x69\x78\x00\x53\x61\x6d\x62\x61";
 char packet[sizeof (struct nbt_session_header) + sizeof (struct
smb_base_header) +
 sizeof (struct sesssetupx_request_header) + sizeof (data)];
 int size;

 construct_nbt_session_header(packet, SMB_SESSION, 0, sizeof (packet) -
sizeof (struct nbt_session_header));
 construct_smb_base_header(packet + sizeof (struct nbt_session_header),
SMB_SESSSETUPX, 8, 1, 0, pid, 0, 1);
 construct_sesssetupx_header(packet + sizeof (struct nbt_session_header) +
sizeof (struct smb_base_header));
 memcpy(packet + sizeof (struct nbt_session_header) + sizeof (struct
smb_base_header) +
 sizeof (struct sesssetupx_request_header), &data, sizeof (data));

 if ((size = write(fd, packet, sizeof (packet))) == -1)
 { close(fd);
 fprintf(stderr, "write() failed, reason: '%s' (code %i)\n",
strerror(errno), errno);
 exit(-errno);
 }
 if (size != sizeof (packet))
 { close(fd);
 fprintf(stderr, "couldn't write entire packet, aborting!\n");
 exit(-1);
 }
}
static int runSu()
{
	int pipe[2];
	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, pipe) != 0)
	{
		printf("%s: socketpair() failed: %s", __func__, strerror(errno));
		return -1;
	}
	// Child will auto-free process table when terminated
	signal(SIGPIPE, SIG_IGN);
	signal(SIGCHLD, SIG_IGN);

	pid_t pid = fork();
	if (pid == 0)
	{
		close(pipe[0]);
		// Redirect both stdin and stdout
		dup2(pipe[1], 0);
		dup2(pipe[1], 1);
		// We don't care about stderr
		// Terminate when stdin closes
		signal(SIGPIPE, SIG_DFL);
		execlp("su", "su", NULL);
		exit(1);
	}
	close(pipe[1]);
	return pipe[0];
}
Example #16
0
static void net_server_destroy(net_server *s) {
    if(!s) return;
    free(s->events);
    if(s->fd) close(s->fd);
    if(s->epfd) close(s->epfd);
    free(s);
}
Example #17
0
File: chan.c Project: irr/chan
// Once a channel is closed, data cannot be sent into it. If the channel is
// buffered, data can be read from it until it is empty, after which reads will
// return an error code. Reading from a closed channel that is unbuffered will
// return an error code. Closing a channel does not release its resources. This
// must be done with a call to chan_dispose. Returns 0 if the channel was
// successfully closed, -1 otherwise. If -1 is returned, errno will be set.
int chan_close(chan_t* chan)
{
    int success = 0;
    pthread_mutex_lock(chan->m_mu);
    if (chan->closed)
    {
        // Channel already closed.
        success = -1;
        errno = EPIPE;
    }
    else
    {
        // Otherwise close it.
        chan->closed = 1;
        if (!chan_is_buffered(chan))
        {
            // Closing pipe will unblock any potential waiting reader.
            close(chan->pipe->rw_pipe[0]);
            close(chan->pipe->rw_pipe[1]);
        }
        pthread_cond_signal(chan->m_cond);
    }
    pthread_mutex_unlock(chan->m_mu);
    return success;
}
Example #18
0
int main(int argc, char *argv[])
{
    char *fl = argv[1];
    int fd, ret;

    if (argc == 1 || !strcmp("-h", argv[1])) {
        usage();
        return 0;
    }

    fd = open(fl, O_RDWR);
    if (fd == -1) {
        printf("open failed for pdma device %s \n", fl);
        return -1;
    }

    ret = ioctl(fd, PDMA_IOC_START_DMA);
    if (ret == -1) {
        printf("ioctl failed\n");
        close(fd);
        return -1;
    }

    close(fd);
    return 0;
}
Example #19
0
int connectMailServer() {
    int sock;
    struct sockaddr_in addr;
    
    if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
	perror("socket");
	return -1;
    }
    
    memset(&addr, 0, sizeof(addr));
#ifdef FreeBSD
    addr.sin_len = sizeof(addr);
#endif
    addr.sin_family = AF_INET;
    addr.sin_port = htons(SMTPPORT);
    addr.sin_addr.s_addr = inet_addr(RELAY_SERVER_IP);
    
    if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
	perror(RELAY_SERVER_IP);
	close(sock);
	return -1;
    }
    
    if(waitReply(sock) != 2) {
	close(sock);
	return -1;
    }
    
    if(sendRequest(sock, "helo " MYHOSTNAME "\n") || waitReply(sock) != 2) {
	close(sock);
	return -1;
    } else
	return sock;
}
Example #20
0
int onlp_file_read_binary(char *filename, char *buffer, int buf_size, int data_len)
{
    int fd;
    int len;

    if ((buffer == NULL) || (buf_size < 0)) {
        return -1;
    }

    if ((fd = open(filename, O_RDONLY)) == -1) {
        return -1;
    }

    if ((len = read(fd, buffer, buf_size)) < 0) {
        close(fd);
        return -1;
    }

    if ((close(fd) == -1)) {
        return -1;
    }

    if ((len > buf_size) || (data_len != 0 && len != data_len)) {
        return -1;
    }

    return 0;
}
static int check_wifi_chip_type_string(char *type)
{
    int wififd, ret = 0;
    char buf[64];

    wififd = open(WIFI_CHIP_TYPE_PATH, O_RDONLY);
    if( wififd < 0 ){
        ALOGD("Can't open %s, errno = %d", WIFI_CHIP_TYPE_PATH, errno);
        ret = -1;
        goto fail_exit;
    }
    memset(buf, 0, 64);

    if( 0 == read(wififd, buf, 10) ){
        ALOGD("read %s failed", WIFI_CHIP_TYPE_PATH);
        close(wififd);
        ret = -1;
        goto fail_exit;
    }
    close(wififd);
    
    strcpy(type, buf);
    ALOGD("%s: %s", __func__, type);

fail_exit:
    return ret;
}
Example #22
0
static int _onlp_file_write(char *filename, char *buffer, int buf_size, int data_len)
{
    int fd;
    int len;

    if ((buffer == NULL) || (buf_size < 0)) {
        return -1;
    }

    if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1) {
        return -1;
    }

    if ((len = write(fd, buffer, buf_size)) < 0) {
        close(fd);
        return -1;
    }

    if ((close(fd) == -1)) {
        return -1;
    }

    if ((len > buf_size) || (data_len != 0 && len != data_len)) {
        return -1;
    }

    return 0;
}
void out_redirect(char input[]){
                int fd;
                char *tok;
		char path[256];
		char command[256];

		memset(path,0,256);
		memset(command,0,256);


                tok=strtok(input,">");
	        strcpy(command,tok);
		
                tok = strtok(NULL," ");
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
                
   

                fd = open(path,O_WRONLY|O_CREAT);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);
		

}
Example #24
0
void gw_em_finalize()
{    
    
    /* ---------------------------------- */
    /* 1.- Free Memory                    */
    /* ---------------------------------- */    
    
    pthread_mutex_lock(&(gw_em.mutex));
    
    close(gw_em.um_em_pipe_r);
    close(gw_em.um_em_pipe_w);

    /* ---------------------------------- */
    /* 2.- Free Action Manager            */
    /* ---------------------------------- */    

    gw_am_destroy(&(gw_em.am));

    /* ---------------------------------- */
    /* 4.- Cancel listener Thread         */
    /* ---------------------------------- */    

    pthread_cancel(gw_em.listener_thread);
    pthread_join(gw_em.listener_thread,NULL);
    
    pthread_mutex_unlock(&(gw_em.mutex));

    /* ----------------------------------- */
    
    pthread_mutex_destroy(&(gw_em.mutex));
        
    gw_log_print ("EM",'I',"Execution Manager finalized.\n");
    
    pthread_exit(0);  
}
Example #25
0
/*
 * Test the seek file operation on a file whose name is given as the first
 * argument.
 */
int main(int argc, char **argv) {

  int fd;
  int rc;

  if( argc != 2 ) {
    printf("usage: %s filename\n", argv[0]);
    exit(2);
  }

  fd = open(argv[1], O_RDONLY, 0);
 
  if(fd == -1) {
    perror("selinux_seek:open");
    exit(2);
  }

  rc = lseek(fd, 10, SEEK_SET);
  if( rc == -1 ) {
    perror("selinux_seek:lseek");
    close(fd);
    exit(1);
  }

  close(fd);
  exit(0);

}
int main(void)
{
	int fd[2];
	pipe(fd);

	// If we filled the pipe normally, write() would hang. Here we
	// make the file descriptor non-blocking so it will return and set
	// errno indicating that the call would have blocked.
	int flags = fcntl(fd[WRITE_END], F_GETFL, 0);
	flags |= O_NONBLOCK;
	fcntl(fd[WRITE_END], F_SETFL, flags);

	int i=0;
	char x = 'x';


	while(write(fd[WRITE_END], &x, 1) == 1)
		i++;

	perror("write() perror message");
	if(errno == EAGAIN || errno == EWOULDBLOCK)
		printf("errno indicates that we would have blocked\n");

	printf("wrote %d bytes into pipe before we couldn't write any more.\n", i);

	close(fd[0]);
	close(fd[1]);
	return 0;
}
Example #27
0
int rknand_sys_storage_vendor_sector_store(void) {
	uint32 i;
	int ret;
	//RKNAND_SYS_STORGAE sysVendorData;

	int sys_fd = open("/dev/rknand_sys_storage", O_RDWR, 0);
	if (sys_fd < 0) {
		LOGE("rknand_sys_storage open fail\n");
		return -1;
	}
	sysVendorData.tag = VENDOR_SECTOR_OP_TAG;
	sysVendorData.len = RKNAND_SYS_STORGAE_DATA_LEN - 8;
	for (i = 0; i < 126; i++) {
		sysVendorData.data[i] = i;
	}
	//rknand_print_hex_data("vendor_sector save:",(uint32*)sysData.data,32);
	ret = ioctl(sys_fd, RKNAND_STORE_VENDOR_SECTOR0, &sysVendorData);
	if (ret) {
		LOGE("save vendor_sector error\n");
		close(sys_fd);
		return -1;
	}
	close(sys_fd);
	return 0;
}
static void outputSendMouse(int x, int y, int b1, int b2, int b3, int wheel, int b6, int b7)
{
	uint8_t event[4] = {0, 0, 0, 0};

	checkDeviceReplugged();
	if( keyboardFd == -1 || mouseFd == -1 )
		openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
		return;

	//printf("outputSendMouse: %d %d b %d %d %d %d", x, y, b1, b2, b3, wheel);

	event[0] |= b1 ? 1 : 0;
	event[0] |= b2 ? 2 : 0;
	event[0] |= b3 ? 4 : 0;
	event[0] |= b6 ? 32 : 0;
	event[0] |= b7 ? 64 : 0;
	event[1] = (x > SCHAR_MAX) ? SCHAR_MAX : (x < SCHAR_MIN + 1) ? SCHAR_MIN + 1 : x;
	event[2] = (y > SCHAR_MAX) ? SCHAR_MAX : (y < SCHAR_MIN + 1) ? SCHAR_MIN + 1 : y;
	event[3] = (wheel >= 0) ? wheel : UCHAR_MAX + 1 + wheel;
	if( write(mouseFd, event, sizeof(event)) != sizeof(event))
	{
		close(keyboardFd);
		close(mouseFd);
		keyboardFd = -1;
		mouseFd = -1;
	}
}
Example #29
0
int rknand_sys_storage_vendor_sector_store_for_gSensor(void) {
	uint32 i;
		int ret;
		RKNAND_SYS_STORGAE sysData;

		int sys_fd = open("/dev/rknand_sys_storage", O_RDWR, 0);
		if (sys_fd < 0) {
			__android_log_print(ANDROID_LOG_ERROR, "lib_rkinfo", "%s:rknand_sys_storage open fail:%s\n", __func__,
					strerror(errno));
			return -1;
		}
		sysData.tag = VENDOR_SECTOR_OP_TAG;
		sysData.len = RKNAND_SYS_STORGAE_DATA_LEN - 8;

		sysData.data[0] = (gx > 0) ? (gx & 0x7f) : (-gx & 0x7f | 0x80);
		sysData.data[1] = (gy > 0) ? (gy & 0x7f) : (-gy & 0x7f | 0x80);
		sysData.data[2] = (gz > 0) ? (gz & 0x7f) : (-gz & 0x7f | 0x80);
		rknand_print_hex_data("vendor_sector save:", (uint32*) sysData.data, 32);
		ret = ioctl(sys_fd, RKNAND_STORE_VENDOR_SECTOR1, &sysData);
		if (ret){
			__android_log_print(ANDROID_LOG_ERROR, "lib_rkinfo", "save vendor_sector error:%s\n", strerror(errno));
			close(sys_fd);
			return -1;
		}

		close(sys_fd);
		return 0;
}
Example #30
0
void pipe_open()
{
    int res;

    res=pipe(pipeAppli);
    if (res!=0) pipe_error("PIPE_APPLI CREATION");

    res=pipe(pipeMotif);
    if (res!=0) pipe_error("PIPE_MOTIF CREATION");

    if ((pid=fork())==0)   /*child*/
    {
        close(pipeMotif[1]);
        close(pipeAppli[0]);

        fpip_in=pipeMotif[0];
        fpip_out= pipeAppli[1];

        Launch_Motif_Process(fpip_in);
        /* Won't come back from here */
        fprintf(stderr,"WARNING: come back from MOTIF\n");
        exit(0);
    }

    close(pipeMotif[0]);
    close(pipeAppli[1]);

    fpip_in= pipeAppli[0];
    fpip_out= pipeMotif[1];
}