Example #1
0
int main(int argc, char *argv[]){

	int shmid;
	key_t key;
	char *shm;
	char *s;


	key = 9877;
	
	shmid = shmget(key, SHSIZE, 0666);
	if(shmid < 0)
	{
		perror("shmget");
		exit(1);
	}

	shm = shmat(shmid, NULL, 0);

	if(shm ==  (char *) -1)
	{
		perror("shmat");
		exit(1);
	}

	for(s = shm; *s != 0; s++)
		printf("%c", *s);

	printf("\n");

	*shm = '*';


	return 0;
}
Example #2
0
void recv_krb5_error(int sockfd,krb5_error *err){

		//if (recv(sockfd, &err->magic,sizeof(err->magic) , 0) == -1){
		//				                   perror("recv");}
		//err->magic=htonl(err->magic);

				if (recv(sockfd, &err->ctime,sizeof(err->ctime) , 0) == -1){
					perror("recv");}
				err->ctime=htonl(err->ctime);

				if (recv(sockfd, &err->cusec,sizeof(err->cusec) , 0) == -1){
											perror("recv");}
				err->cusec=htonl(err->cusec);

				if (recv(sockfd, &err->susec,sizeof(err->susec) , 0) == -1){
											perror("recv");}
				err->susec=htonl(err->susec);

				if (recv(sockfd, &err->stime,sizeof(err->stime) , 0) == -1){
											perror("recv");}
				err->stime=htonl(err->stime);
		recv_principal_data(sockfd,err->server);
		recv_principal_data(sockfd,err->client);
		recv_krb5_data(sockfd,&err->text);
		recv_krb5_data(sockfd,&err->e_data);
				}
Example #3
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);

}
Example #4
0
void init_openssl()
{
    if (!RAND_status()) {
	time_t time_sec = time(NULL);
	if (time_sec == (time_t)-1) {
            perror("time() system call failed");
	    exit(EXIT_FAILURE);
	}
	RAND_seed(&time_sec, sizeof(time_sec));
    }
    while (!RAND_status()) {
#ifdef MINGW
	FILETIME filetime;
	GetSystemTimeAsFileTime(&filetime);
	RAND_seed(&filetime.dwLowDateTime, sizeof(filetime.dwLowDateTime));
#else
        struct timeval tv;
	if (gettimeofday(&tv, NULL) == -1) {
	    perror("gettimeofday() system call failed");
	    exit(EXIT_FAILURE);
        }
	RAND_seed(&tv.tv_usec, sizeof(tv.tv_usec));
#endif
    }
    ERR_load_crypto_strings();
    /* Random seeding in OpenSSL may use some system calls that fail.
     * We should ignore these error codes in future error messages. */
    errno = 0;
}
Example #5
0
main()
{
   int semid;
   struct sembuf semoperation[1];

   /*if( (semid = semget((key_t)SEMKEY, 2, 0666)) < 0)
       perror("Semaphore get error");*/
   if( (semid = semget((key_t)SEMKEY, 1, 0666)) < 0)
       perror("Semaphore get error");

   int shmid;
   int* array;

   if( (shmid = shmget( (key_t)SHMKEY , 10*sizeof(int) , 0666 )) < 0)
       perror("Error");

   array = (int*)shmat(shmid , 0 , 0);

   //semoperation[0].sem_num = 1;
   semoperation[0].sem_num = 0;
   semoperation[0].sem_op = P;
   semoperation[0].sem_flg = SEM_UNDO;
   semop(semid,semoperation,1);

   int i;
   for(i = 0; i < 10; i++)
     array[i] += 100;

   printf("\nSecond child completed adding 100(pid = %d).\n" , getpid());

}
Example #6
0
bitmap_t *bitmap_resize(bitmap_t *bitmap, size_t old_size, size_t new_size)
{
	/* resize if mmap exists else new mmap */
	if (bitmap->array != NULL) {
		bitmap->array = mremap(bitmap->array, old_size, new_size,
					MREMAP_MAYMOVE);
		if (bitmap->array == MAP_FAILED) {
			perror("Error resizing mmap");
			free_bitmap(bitmap);
			return NULL;
		}
	}

	if (bitmap->array == NULL) {
		bitmap->array = mmap(0, new_size, PROT_READ | PROT_WRITE,
				MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
		if (bitmap->array == MAP_FAILED) {
			perror("Error init mmap");
			free_bitmap(bitmap);
			return NULL;
		}
	}

	bitmap->bytes = new_size;
	return bitmap;
}
int main(int argc, char *argv[]) {

	int fd = open("crackme", O_RDONLY);

    if(fd == -1) {
        perror(NULL);
        exit(10);
    }

	struct stat st_fd;
    if(fstat(fd, &st_fd) == -1) {
        perror(NULL);
        exit(11);
    }

	void* ptr = mmap(NULL, st_fd.st_size,
		PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0
	);

	int (*func)(char* str) = (ptr + 0xea0);


	int ret = func(argv[1]);
	printf("%x\n", ret);
	return 0;
}
Example #8
0
static int
force_nomem(void)
{
	struct rlimit rl;
	size_t sz;
	void *hog;

	malloc_trim(0);

	if (getrlimit(RLIMIT_AS, &rl)) {
		perror("Cannot get current AS limit");
		return -1;
	}
	rl.rlim_cur = 0;
	if (setrlimit(RLIMIT_AS, &rl)) {
		perror("Cannot set current AS limit");
		return -1;
	}
	for (sz = 1024; sz; sz -= sizeof(long)) {
		do {
			void *newhog;
			size_t mysz = 0;
			hog = NULL;
			while ( (newhog = realloc(hog, mysz += sz)) )
				hog = newhog;
			if (hog && nhogs < MAXHOGS)
				hogs[nhogs++] = hog;
		} while (hog);
	}

	return 0;
}
Example #9
0
File: rping.c Project: hkimura/pib
static int rping_bind_server(struct rping_cb *cb)
{
	int ret;

	if (cb->sin.ss_family == AF_INET)
		((struct sockaddr_in *) &cb->sin)->sin_port = cb->port;
	else
		((struct sockaddr_in6 *) &cb->sin)->sin6_port = cb->port;

	ret = rdma_bind_addr(cb->cm_id, (struct sockaddr *) &cb->sin);
	if (ret) {
		perror("rdma_bind_addr");
		return ret;
	}
	DEBUG_LOG("rdma_bind_addr successful\n");

	DEBUG_LOG("rdma_listen\n");
	ret = rdma_listen(cb->cm_id, 3);
	if (ret) {
		perror("rdma_listen");
		return ret;
	}

	return 0;
}
Example #10
0
void*
mem_alloc(const char *unit, size_t nbytes)
{
  Mem_t *entry;

  entry = (Mem_t *)malloc(sizeof(Mem_t));
  if (!entry) {
    perror("malloc");
    return NULL;
  }
  entry->size = nbytes;
  entry->unit = (char*)malloc(strlen(unit)+1);
  if (!entry->unit) {
    perror("malloc");
    free(entry);
    return NULL;
  }
  memcpy(entry->unit, unit, strlen(unit)+1);
  entry->start = malloc(nbytes);
  if (!entry->start) {
    perror("malloc");
    free(entry->unit);
    free(entry);
    return NULL;
  }
  entry->next = memlist;
  memlist = entry;
  return entry->start;
}
Example #11
0
/*
 * Set up the supplied context by creating and binding its netlink socket.
 * Returns 0 for success, 1 for failure.
 */
int API
routeup_setup (struct routeup *rtc)
{
  struct sockaddr_nl sa;

  memset (&sa, 0, sizeof (sa));
  sa.nl_family = AF_NETLINK;
  sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE;

  rtc->netlinkfd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  if (rtc->netlinkfd < 0)
    {
      perror ("netlink socket() failed");
      return 1;
    }
  if (bind (rtc->netlinkfd, (struct sockaddr *) &sa, sizeof (sa)) < 0)
    {
      perror ("netlink bind() failed");
      close (rtc->netlinkfd);
      return 1;
    }
  if (fcntl (rtc->netlinkfd, F_SETFL, O_NONBLOCK) < 0)
    {
      perror ("netlink fcntl(O_NONBLOCK) failed");
      close (rtc->netlinkfd);
      return 1;
    }
  return 0;
}
bool CopyElfFromFile(map_info_t* info, bool* file_copied) {
  std::string cur_name = basename(info->name.c_str());
  if (*file_copied) {
    info->name = cur_name;
    return true;
  }

  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(info->name.c_str(), "r"), &fclose);
  if (fp == nullptr) {
    perror((std::string("Cannot open ") + info->name).c_str());
    return false;
  }

  std::unique_ptr<FILE, decltype(&fclose)> output(fopen(cur_name.c_str(), "w+"), &fclose);
  if (output == nullptr) {
    perror((std::string("Cannot create file " + cur_name)).c_str());
    return false;
  }
  std::vector<uint8_t> buffer(10000);
  size_t bytes;
  while ((bytes = fread(buffer.data(), 1, buffer.size(), fp.get())) > 0) {
    size_t bytes_written = fwrite(buffer.data(), 1, bytes, output.get());
    if (bytes_written != bytes) {
      printf("Bytes written doesn't match bytes read: read %zu, written %zu\n", bytes,
             bytes_written);
      return false;
    }
  }

  // Replace the name with the new name.
  info->name = cur_name;

  return true;
}
Example #13
0
int readHeader(int fd, int *rows, int *cols, unsigned int *start) 
{
  BITMAPFILEHEADER bmfh;
  BITMAPINFOHEADER bmih;

  if(myread(fd, ((char*)&bmfh)+2, sizeof(bmfh)-2) <= 0) {
    perror("Can't read BITMAPFILEHEADER");
    return -2;
  }
  if(myread(fd, (char*)&bmih, sizeof(bmih)) <= 0) {
    perror("Can't read BITMAPINFOHEADER");
    return -3;
  }

  if(bmih.biCompression != 0) {
    fprintf(stderr, "Can't read compressed bmp");
    return -4;
  }
  if(bmih.biBitCount != 24) {
    fprintf(stderr, "Can't handle bmp other than 24-bit");
    return -5;
  }

  *rows = bmih.biHeight;
  *cols = bmih.biWidth;
  *start = bmfh.bfOffBits;

  return 0;
}
Example #14
0
// return thread id
static int r_debug_native_attach (RDebug *dbg, int pid) {
#if 0
	if (!dbg || pid == dbg->pid)
		return dbg->tid;
#endif
#if __linux__
	return linux_attach (dbg, pid);
#elif __WINDOWS__ && !__CYGWIN__
	int ret;
	HANDLE process = w32_open_process (PROCESS_ALL_ACCESS, FALSE, pid);
	if (process != (HANDLE)NULL && DebugActiveProcess (pid)) {
		ret = w32_first_thread (pid);
	} else {
		ret = -1;
	}
	ret = w32_first_thread (pid);
	CloseHandle (process);
	return ret;
#elif __CYGWIN__
	#warning "r_debug_native_attach not supported on this platform"
	return -1;
#elif __APPLE__
	return xnu_attach (dbg, pid);
#elif __KFBSD__
	if (ptrace (PT_ATTACH, pid, 0, 0) != -1) perror ("ptrace (PT_ATTACH)");
	return pid;
#else
	int ret = ptrace (PTRACE_ATTACH, pid, 0, 0);
	if (ret != -1) {
		perror ("ptrace (PT_ATTACH)");
	}
	return pid;
#endif
}
Example #15
0
/**
 * Tworzy połączenie TCP
 */
int create_connection()
{
    int sock;
    socklen_t length;
    struct sockaddr_in6 server;
    sock = socket(AF_INET6, SOCK_STREAM, 0);
    if (sock == -1)
    {
        perror("Blad socketu");
        exit(1);
    }
    server.sin6_family = AF_INET6;
    server.sin6_addr = in6addr_any;
    server.sin6_port = htons(8888);
    if (bind(sock, (struct sockaddr *) &server,sizeof server) == -1)
    {
        perror("Blad bindingu socketu");
        exit(1);
    }

    length = sizeof(server);
    if (getsockname(sock,(struct sockaddr *) &server, &length) == -1)
    {
        perror("Blad getsockname");
        exit(1);
    }
    printf("\nPort nasluchujacy: %d\n", ntohs(server.sin6_port));
    return sock;

}
Example #16
0
File: qsnd.c Project: Og192/CPro
int main(int argc,char **argv)
{
	int qid;
	int len;
	key_t key;
	key = 113;
	struct msg pmsg;

	if( (qid = msgget(key,IPC_CREAT | 0666)) < 0){
		perror("msgget");
		exit(EXIT_FAILURE);
	}

	printf("Enter message to post <%d>:\n",qid);
	if( (fgets((&pmsg)->msg_text,BUFSZ,stdin)) == NULL){
		puts("no message to post");
		exit(EXIT_SUCCESS);
	}

	pmsg.msg_type = getpid();

	len = strlen(pmsg.msg_text);
	if( (msgsnd(qid,&pmsg,len,0)) < 0){
		perror("msgsnd");
		exit(EXIT_FAILURE);
	}

	puts("message poeted");
	exit(EXIT_SUCCESS);
}
Example #17
0
static void open_audio_out()
{
  int fd;
  int flags = O_WRONLY;
  if( nonblock )
  {
    flags |= O_NONBLOCK;
  }
  fd = open("/dev/dsp", flags, 0777);
  if( fd < 0 )
  {
    perror("open dsp");
  }
  else
  {
    int setting, result;

    ioctl(fd, SNDCTL_DSP_RESET);
    setting = 0x00040009;
    result = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &setting);
    if( result )
    {
      perror("ioctl(SNDCTL_DSP_SETFRAGMENT)");
    }
    set_format(fd, 0x10, 2, rate);

    fdw = fd;
  }
}
Example #18
0
static int
test (const char *name)
{
  DIR *dirp;
  struct dirent *entp;
  int retval = 0;

  puts (name);

  dirp = opendir (name);
  if (dirp == NULL)
    {
      perror ("opendir");
      return 1;
    }

  errno = 0;
  while ((entp = readdir (dirp)) != NULL)
    printf ("%s\tfile number %lu\n",
	    entp->d_name, (unsigned long int) entp->d_fileno);

  if (errno)
    {
      perror ("readdir");
      retval = 1;
    }

  if (closedir (dirp) < 0)
    {
      perror ("closedir");
      retval = 1;
    }

  return retval;
}
Example #19
0
int main(){

	int shmflag=PROT|IPC_CREAT; 
	int shmid; // ID du segment de mémoire partagée
	shmid = shmget(IPC_PRIVATE,5*sizeof(int),shmflag); // Création d'un segment de mémoire partagée de taille 5 entiers
	
	if(shmid == -1) perror("Création échouée");
	else printf("Segment mémoire créé.\n");

	int *idx_w; // Index d'écriture
	int *idx_r; // Index de lecture
	idx_w=shmat(shmid,0,shmflag); // On attache le segment mémoire à l'index d'écriture
	idx_r=shmat(shmid,0,shmflag); // On attache le segment mémoire à l'index de lecture

	pid_t fils;

	// Variables du fils
	int i, j=0;
	// Variables du père
	int k, l=0;

	// Création des sémaphores
	init_semaphore();
	// Initialisation des sémaphores
	val_sem(sem_vide,5); // Au début, il y a 5 emplacements libres dans le buffer 
	val_sem(sem_plein,0); // Au début, il n'y a pas de message en attente

	switch (fils=fork()){
		case -1:
			perror("Probleme fork");
			break;	
		case 0: // Fils	- PRODUCTEUR
			for (i = 1; i < 51; i++) // Pour afficher 50 valeurs 
			{
				P(sem_vide); // On applique P au sémaphore comptant le nombre d'emplacement libres
				idx_w[j]=i;
				printf("Produit : %d\n", idx_w[j]);
				j++;
				j = j%5; // Le buffer est circulaire de taille 5, on accède uniquement aux cases 0 1 2 3 et 4
				V(sem_plein); // On applique V au sémaphore comptant le nombre de messages en attente
			}
			shmdt(idx_w); // Détachement du segment mémoire
			break; 
		default: // Père - CONSOMMATEUR
			for (k = 1; k < 51; k++)
			{
				P(sem_plein); // On applique P au sémaphore comptant le nombre de messages en attente
				printf("Consommé : %d\n", idx_r[l]);	
				l++;
				l = l%5; // Le buffer est circulaire de taille 5, on accède uniquement aux cases 0 1 2 3 et 4
				V(sem_vide); // On applique V au sémaphore comptant le nombre d'emplacement libres
			}
			wait(0); // On attend la fin du fils
			shmdt(idx_r); // Détachement du segment mémoire
			shmctl(shmid, IPC_RMID,0); // Destruction du segment mémoire
			printf("Segment mémoire supprimé.\n");
			detruire_semaphore();
	}
	return 0;
}
Example #20
0
void handleClient(void *socketPointer) {
    int sock = (int)socketPointer;
    int error;
    char buffer[1024];
    char line[1024];
    struct Message receivedMessage, sentMessage;
    FILE *file;
    error = recv(sock, buffer, sizeof(buffer), 0);
    if (error < 0) {
        perror("Failed to receive");
        exit(1);
    }
    memcpy(&receivedMessage, buffer, sizeof(receivedMessage));

    file = fopen(receivedMessage.content, "r");
    while (fgets(line, sizeof(line), file)) {
        pthread_mutex_lock(&mutex);
        if (strlen(line) > strlen(longestLine)) {
            strcpy(longestLine, line);
        }
        strcpy(sentMessage.content, longestLine);
        pthread_mutex_unlock(&mutex);
    }
    fclose(file);
    memcpy(buffer, &sentMessage, sizeof(sentMessage));
    error = send(sock, buffer, sizeof(buffer), 0);
    if (error < 0) {
        perror("Failed to send");
        exit(1);
    }
    close(sock);
}
Example #21
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 #22
0
int set_up_socket(struct addrinfo *server){
    int sockfd;
    struct addrinfo hints, *p;
    int x;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_DGRAM;

    if ((x = getaddrinfo(NAME_SERVER, DNS_PORT, &hints, &server)) != 0) {
        perror("getaddrinfo:\n");
        return 1;
    }

    // loop through all the results and make a socket
    for(p = server; p != NULL; p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1){
            perror("talker: socket");
            continue;
        }
        server = p;
        break;
    }

    if (p == NULL) {
        printf("bind failed\n");
        return 1;
    }

    

    return sockfd;
}
Example #23
0
int silence()
{
	int fd = open("/dev/null", O_RDWR, 0);
	if(fd == -1) return TRACKD_ERR;

	if(dup2(fd, STDIN_FILENO) < 0) {
		perror("dup2 stdin");
		return TRACKD_ERR;
	}

	if(dup2(fd, STDOUT_FILENO) < 0) {
		perror("dup2 stdout");
		return TRACKD_ERR;
	}

	if(dup2(fd, STDERR_FILENO) < 0) {
		perror("dup2 stderr");
		return TRACKD_ERR;
	}

	if (fd > STDERR_FILENO) {
		if(close(fd) < 0) {
			perror("close");
			return TRACKD_ERR;
		}
	}
	return TRACKD_OK;
}
Example #24
0
File: filter.c Project: apexo/bk
int filter_rule_add(filter_t *filter, int include, const char *pattern) {
	filter_rule_t **rules = realloc(filter->rules, sizeof(filter_rule_t*)*(filter->rule_count+1));
	if (!rules) {
		perror("out of memory");
		return -1;
	}
	filter->rules = rules;

	filter_rule_t *rule = malloc(sizeof(filter_rule_t));
	if (!rule) {
		perror("out of memory");
		return -1;
	}
	rules[filter->rule_count] = rule;

	if (filter_rule_init(rule, include, pattern)) {
		fprintf(stderr, "filter_rule_init failed\n");
		free(rule);
		return -1;
	}
	filter->rule_count++;

	if (_filter_match_add(filter->match, rule, 0)) {
		fprintf(stderr, "_filter_match_add failed\n");
		filter_rule_free(rule);
		free(rule);
		return -1;
	}

	return 0;
}
Example #25
0
void sharedMemory()
{

    // make the key:
    if ((key = ftok("file", 'R')) == -1) {
        perror("ftok");
        exit(1);
    }

    // connect to (and possibly create) the segment:
    if ((shmid = shmget(key, sizeof(pthread_t), 0644 | IPC_CREAT)) == -1) {
        perror("shmget");
        exit(1);
    }

    // attach to the segment to get a pointer to it:
    cnt = shmat(shmid, (void *)0, 0);
    if (cnt == (int *)(-1)) {
        perror("shmat");
        exit(1);
    }

    // read or modify the segment, based on the command line:
	*cnt = 0;
    printf("segment contains: \"%d\"\n", *cnt);

}
Example #26
0
int nexthashrec(FILE * fp, struct hashdb_rec *rec)
{

	int recordlength, wordlen;

	if (fread(&rec->rec_size, sizeof(rec->rec_size), 1, fp) != 1) {
	
		perror("fread");
		return -1;
	}

	recordlength = abs(rec->rec_size);
	wordlen = recordlength - (sizeof(rec->pmk) + sizeof(rec->rec_size));

	if (wordlen > 63 || wordlen < 8) {
		fprintf(stderr, "Invalid word length: %d\n", wordlen);
		return -1;
	}

	/* hackity, hack, hack, hack */
	rec->word = password_buf;

	if (fread(rec->word, wordlen, 1, fp) != 1) {
		perror("fread");
		return -1;
	}

	if (fread(rec->pmk, sizeof(rec->pmk), 1, fp) != 1) {
		perror("fread");
		return -1;
	}

	return recordlength;
}
Example #27
0
main()
{
    char c;
    int shmid;
    key_t key;
    int *shm, *s;

    key = 7000;
     printf("hei1");

    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
        perror("shmget");
        exit(1);
    }
        printf("hei2");
    if ((shm = shmat(shmid,0, 0666)) == NULL) {
        perror("shmat");
        exit(1);
    }

     s = shm;

    for (c = 'a'; c <= 'z'; c++)
        *s++ = c;
    *s = NULL;

		
    while (*shm != '*')
        sleep(1);

    exit(0);
}
int main(void) {
	pid_t pid;

	pid = fork();
	switch (pid) {
	case -1:
		perror("fork()"); //fork 함수를 통해 자식 프로세스를 생성합니다.
		exit(-1);
		break;
	case 0: /* child process */
		printf("CHILD PROCESS\n");
		//자식 프로세스에서 execlp 함수를 이용하여 ex07 실행 코드를 ls 명령의 실행 코드로 교체하여 실행합니다. 
		execlp("ls", "ls", "-l", (char *)0);
		
		//execlp 함수의 수행결과와 상관없이 무조건 perror() 함수를 호출하고 있습니다.
		//execlp 함수가 교체에 실패하면 perror()을 수행하지만 교체에 성공한다면 perror()은 존재하지 않기 때문에 이렇게 실행해도 됩니다. 
		perror("execlp"); 
		exit(0);
		break;
	default: /* Parent Process */
		wait(NULL);
		printf("Child is dead\n");
		break;
	}
	return 0;
}
Example #29
0
char *
TimeString (time_t start, time_t end)
{
  static char datestr[255];
  char t1[64], t2[64];
  struct tm *tbuff;

  if (start)
    {
      tbuff = localtime (&start);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t1, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      tbuff = localtime (&end);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t2, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      snprintf (datestr, 254, "%s - %s", t1, t2);
    }
  else
    {
      snprintf (datestr, 254, "Time Window unknown");
    }
  datestr[254] = 0;
  return datestr;
}
Example #30
0
boolean tcp_set_keep_alive_mode(rdpTcp* tcp)
{
#ifndef _WIN32
	uint32 option_value;
	socklen_t option_len;

	option_value = 1;
	option_len = sizeof(option_value);

	if (setsockopt(tcp->sockfd, SOL_SOCKET, SO_KEEPALIVE, (void*) &option_value, option_len) < 0)
	{
		perror("setsockopt() SOL_SOCKET, SO_KEEPALIVE:");
		return false;
	}

#ifdef TCP_KEEPIDLE
	option_value = 5;
	option_len = sizeof(option_value);

	if (setsockopt(tcp->sockfd, IPPROTO_TCP, TCP_KEEPIDLE, (void*) &option_value, option_len) < 0)
	{
		perror("setsockopt() IPPROTO_TCP, SO_KEEPIDLE:");
		return false;
	}
#endif
#endif

	return true;
}