Ejemplo n.º 1
0
Archivo: shm_man.c Proyecto: 1GHL/2013y
void handler(int sig, siginfo_t *info, void *ctx)
{

  int shmid=0;
 
  syslog(LOG_DEBUG,"daemon: handler %d %d %d",sig,info->si_int,info->si_pid);
  if((shmid= info->si_int) != -1)
    {
      syslog(LOG_DEBUG,"daemon: from :%d  shmid :%d",info->si_pid,shmid);
      read_shm(info->si_pid,shmid);
    }
}
Ejemplo n.º 2
0
/* Make reads even "more" of a race condition */
ssize_t slowread(medium_s *medium, void *buf, size_t size)
{
    size_t i;
    ssize_t status;
    
    start_timer(WAIT_TIME);
    for(i = 0; i < size; i++) {
        status = read_shm(medium, buf+i, i, sizeof(char));
        if(status == EINTR) {
            pthread_cancel(timer_thread);
            return EINTR;
        }
    }
    pthread_cancel(timer_thread);
    return 0;
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
	struct radclock *clock;
	struct timeval tv;
	int err;

	clock = radclock_create();
	radclock_init(clock);

	read_shm(clock);

	err = radclock_gettimeofday(clock, &tv);
	fprintf(stdout, "UNIX time: %d.%d with error code: %d\n",
			tv.tv_sec, tv.tv_usec, err);

	radclock_destroy(clock);

	return (0);
}
Ejemplo n.º 4
0
static gchar *
get_session_address_dbus_launch (GError **error)
{
  HANDLE autolaunch_mutex, init_mutex;
  char *address = NULL;
  wchar_t gio_path[MAX_PATH+1+200];

  autolaunch_mutex = acquire_mutex (DBUS_AUTOLAUNCH_MUTEX);

  init_mutex = acquire_mutex (UNIQUE_DBUS_INIT_MUTEX);

  if (is_mutex_owned (DBUS_DAEMON_MUTEX))
    address = read_shm (DBUS_DAEMON_ADDRESS_INFO);

  release_mutex (init_mutex);

  if (address == NULL)
    {
      gio_path[MAX_PATH] = 0;
      if (GetModuleFileNameW (_g_io_win32_get_module (), gio_path, MAX_PATH))
	{
	  PROCESS_INFORMATION pi = { 0 };
	  STARTUPINFOW si = { 0 };
	  BOOL res;
	  wchar_t gio_path_short[MAX_PATH];
	  wchar_t rundll_path[MAX_PATH*2];
	  wchar_t args[MAX_PATH*4];

	  GetShortPathNameW (gio_path, gio_path_short, MAX_PATH);

	  GetWindowsDirectoryW (rundll_path, MAX_PATH);
	  wcscat (rundll_path, L"\\rundll32.exe");
	  if (GetFileAttributesW (rundll_path) == INVALID_FILE_ATTRIBUTES)
	    {
	      GetSystemDirectoryW (rundll_path, MAX_PATH);
	      wcscat (rundll_path, L"\\rundll32.exe");
	    }

	  wcscpy (args, L"\"");
	  wcscat (args, rundll_path);
	  wcscat (args, L"\" ");
	  wcscat (args, gio_path_short);
#if defined(_WIN64) || defined(_M_X64) || defined(_M_AMD64)
	  wcscat (args, L",g_win32_run_session_bus");
#elif defined (_MSC_VER)
	  wcscat (args, L",_g_win32_run_session_bus@16");
#else
	  wcscat (args, L",g_win32_run_session_bus@16");
#endif

	  res = CreateProcessW (rundll_path, args,
				0, 0, FALSE,
				NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW | DETACHED_PROCESS,
				0, NULL /* TODO: Should be root */,
				&si, &pi);
	  if (res)
	    address = read_shm (DBUS_DAEMON_ADDRESS_INFO);
	}
    }

  release_mutex (autolaunch_mutex);

  if (address == NULL)
    g_set_error (error,
		 G_IO_ERROR,
		 G_IO_ERROR_FAILED,
		 _("Session dbus not running, and autolaunch failed"));

  return address;
}
Ejemplo n.º 5
0
void send_private( int sno ) 
{
   int i ;	
   Position Pos, TmpPos;
   char touser[ NAMSIZ ], Buf[ MAXBUF ], Tmp[ MAXBUF ] ;

   Pos = L_Client->Next ;
   while (  Pos != NULL ) {
	 if (sempid(Pos->Element->c_semid, 0)==Pos->Element->c_pid) {
		read_shm ( Pos->Element->c_semid, Pos->Element->c_shmid, Buf ) ;
		printf ( "Message Got :%s:\n", Buf ) ;
		if ( strcmp ( Buf, "Quit" ) == 0 ) {
			write_shm ( Pos->Element->c_semid, Pos->Element->c_shmid, "Finished" ) ;
			if ( waitpid ( Pos->Element->c_pid, NULL, 0 ) == -1 )
				err_sys ( "waitpid error" ) ;
			semdel ( Pos->Element->c_semid ) ;
			shmdel ( Pos->Element->c_shmid ) ;
			close ( Pos->Element->c_fd ) ;
			printf ( "Removing the user from List >>%s<<\n", Pos->Element->c_name ) ;
			Delete ( Pos->Element->c_name, L_Client ) ;
			c_count-- ;
			printf ( "Client Process Removed\n" ) ;
			return ;
		} else if ( strcmp ( Buf, "list" ) == 0 ) {
		    printf ( "Got Message from %s To List Users\n", Pos->Element->c_name ) ;
			TmpPos = L_Client->Next ;
			while ( TmpPos != NULL ) {
				sprintf ( Tmp, "%s\n", TmpPos->Element->c_name ) ;
				send ( Pos->Element->c_fd, Tmp, strlen ( Tmp ), MSG_DONTWAIT ) ;
				TmpPos = TmpPos->Next ;
			}
		    send( Pos->Element->c_fd, prompt[0], strlen(prompt[0]), MSG_DONTWAIT);
			write_shm ( Pos->Element->c_semid, Pos->Element->c_shmid, "No Data" ) ;
			return ;
		} else {
			touser[ 0 ] = '\0' ;
			for ( i = 1; Buf[ i ] != '>'; i++ )
				touser[ i-1 ] = Buf[ i ];
			touser[ i-1 ] = '\0' ;
			printf ( "Searching For User %s\n", touser ) ;
			TmpPos = Find ( touser, L_Client ) ;
			if ( TmpPos == NULL ) {
				printf ( "%s: User Not Available\n", touser ) ;
				sprintf ( Tmp, "%s: User Not Available\n>>", touser ) ;
				send ( Pos->Element->c_fd, Tmp, strlen ( Tmp ), MSG_DONTWAIT ) ;
				write_shm ( Pos->Element->c_semid, Pos->Element->c_shmid, "No Data" ) ;
				return ;
			}
			printf ( "%s: User Available\n", touser ) ;
			sprintf ( Tmp, "PRIVATE Message From %s: %s\n>>", Pos->Element->c_name, &Buf[ i+1 ] ) ;
			printf ( "PRIVATE Message From %s: %s\n", Pos->Element->c_name, &Buf[ i+1 ] ) ;
			send ( TmpPos->Element->c_fd, Tmp, strlen ( Tmp ), MSG_DONTWAIT ) ;
			sprintf ( Tmp, "Message Has been recevied by %s\n>>", touser ) ;
			printf ( "Message Has been recevied by %s\n", touser ) ;
			send ( Pos->Element->c_fd, Tmp, strlen ( Tmp ), MSG_DONTWAIT ) ;
			write_shm ( Pos->Element->c_semid, Pos->Element->c_shmid, "No Data" ) ;
		}
	 }
   	Pos = Pos->Next ;
  }
}
Ejemplo n.º 6
0
int handle_client ( struct client_ds *cds )
{
   int retval ;
   int action = -1 ;
   int savesig ;
   char tmp[MAXBUF], buf[MAXBUF], touser[ NAMSIZ ] ;
   struct sigaction act;
   int csd ;

   csd = cds->c_fd ;
   if ( signal ( SIGUSR1, sigusr ) == SIG_ERR )
	    err_sys ( "signal error" ) ;

   sprintf ( buf, "Client Name: %s\n", cds->c_name ) ;
   send(csd, buf, strlen(buf), MSG_DONTWAIT);
   send( csd, prompt[1], strlen(prompt[1]), MSG_DONTWAIT );
   if ( sigsetjmp ( c_env, savesig ) == 1 ) {
		read_shm ( p_semid, p_shmid, buf ) ;
        send(csd, buf, strlen(buf), MSG_DONTWAIT);
		send( csd, prompt[0], strlen(prompt[0]), MSG_DONTWAIT );
   }
   while(action != 2){
     if((retval = recv(csd, buf, sizeof(buf), 0)  ) < 0)
       err_sys("Reading stream message\n");
     buf[retval]='\0';

     if (strcmp(buf,"help\n")==0)
       action=0;
	 if (strcmp(buf,"list\n")==0)
	   action=7;
     if (strcmp(buf,"pub\n")==0)
       action=1;
     if (strcmp(buf,"quit\n")==0 || retval==0)
       action=2;
	 if (strcmp(buf,"pri\n")==0)
	   action=1;	 
     if (strcmp(buf,"\n")==0)
       action=3;
     switch (action) {
		 case 0:
		   send(csd, prompt[1], strlen(prompt[1]), MSG_DONTWAIT);
		   action=-1;
		   break;
		 case 1:
	 	   if (strcmp(buf,"pri\n")==0) {
		      send(csd, prompt[4], strlen(prompt[4]), MSG_DONTWAIT);
			  action = 5 ;
		   } else {
		      send(csd, prompt[2], strlen(prompt[2]), MSG_DONTWAIT);
		      action = 4 ;
		   }
		   break;
		 case 2:
		   write_shm ( cds->c_semid, cds->c_shmid, "Quit" ) ;
		   kill ( getppid( ), SIGUSR2 ) ;
		   while ( sempid( cds->c_semid, 0 ) == getpid ()  )
			   sleep ( 1 ) ;
		   printf("\nEnding connection ...\n");
		   return 0 ;
		   break;
		 case 3:
		   send(csd, prompt[3], strlen(prompt[3]), MSG_DONTWAIT);
		   action=-1;
		   break;
		 case 4:
		   printf ( "server recevied: %s\n", buf ) ;
		   sprintf ( tmp, "Message From %s: %s\n", cds->c_name, buf ) ;
		   write_shm ( p_semid, p_shmid, tmp ) ;
		   kill ( 0, SIGUSR1 ) ;
		   action=3;
		   break ;
		 case 5:
		   buf[ strlen( buf ) - 1 ] = '\0' ;
		   printf ( "getting private message for %s\n", buf ) ;
		   sprintf ( touser, "%s",  buf ) ;
		   send(csd, prompt[2], strlen(prompt[2]), MSG_DONTWAIT);
		   action=6;
		   break;
		 case 6:
		   sprintf ( tmp, "<%s>%s", touser, buf ) ;
		   write_shm ( cds->c_semid, cds->c_shmid, tmp ) ;
		   kill ( getppid( ), SIGUSR2 ) ;
		   action=3;
		   break ;
		 case 7:  
		   write_shm ( cds->c_semid, cds->c_shmid, "list" ) ;
		   kill ( getppid( ), SIGUSR2 ) ;
		   action=3;
		   break ;
		 default:
		   send(csd, prompt[3], strlen(prompt[3]), MSG_DONTWAIT);
     }
   }
   close(csd);

   return 1 ;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
  bool static_init_ok = false;
  const char *action;
  int err = 0;

  self = os_program_name(argv[0]);

  if (argc <= 1)
  {
      usage();
      err = 1;
      goto done;
  }

  err = examsg_static_init(EXAMSG_STATIC_GET);
  if (err != 0)
  {
      fprintf(stderr, "examsg_static_init failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }
  static_init_ok = true;

  mh = examsgInit(EXAMSG_TEST_ID);
  if (!mh)
  {
      fprintf(stderr, "examsgInit failed\n");
      goto done;
  }

  err = examsgAddMbox(mh, examsgOwner(mh), 3, EXAMSG_MSG_MAX);
  if (err != 0)
  {
      fprintf(stderr, "examsgAddMbox failed: %s (%d)\n", exa_error_msg(-err), err);
      goto done;
  }

  action = argv[1];
  if (strcmp(action, "is_fs_mounted") == 0)
  {
      int m;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      m = fsd_is_fs_mounted(mh, argv[2]);
      if (m < 0)
          err = m;
  }
  else if (strcmp(action, "is_mountpoint_used") == 0)
  {
      int u;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      u = fsd_is_mountpoint_used(mh, argv[2]);
      if (u < 0)
          err = u;
  }
  else if (strcmp(action, "prepare_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[2],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_prepare(mh, &fs);
  }
  else if (strcmp(action, "mount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[3], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[3]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[4], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[4]);
          goto done;
      }

      err = fsd_mount(mh, &fs, 1 , 0, argv[5], argv[6]);
  }
  else if (strcmp(action, "umount") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.mountpoint, argv[2], sizeof(fs.mountpoint));
      if (sz >= sizeof(fs.mountpoint))
      {
          fprintf(stderr, "Invalid mountpoint: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.devpath, argv[3], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[3]);
          goto done;
      }

      err = fsd_umount(mh, &fs, argv[5], argv[6]);
  }
  else if (strcmp(action, "unload") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      sz = os_strlcpy(fs.fstype, argv[2], sizeof(fs.fstype));
      if (sz >= sizeof(fs.fstype))
      {
          fprintf(stderr, "Invalid fs type: '%s' (too long)\n", argv[2]);
          goto done;
      }

      err = fsd_unload(mh, &fs);
  }
  else if (strcmp(action, "create_local") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_fs_create_local(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "create_gfs") == 0)
  {
      fs_data_t fs;
      size_t sz;

      if (argc != 7)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype))
      sz = os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.lock_protocol, argv[3],
                      sizeof(fs.clustered.gfs.lock_protocol));
      if (sz >= sizeof(fs.clustered.gfs.lock_protocol))
      {
          fprintf(stderr, "Invalid lock protocol: '%s' (too long)\n", argv[3]);
          goto done;
      }

      if (to_uint64(argv[4], &fs.sizeKB) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid size: '%s'\n", argv[4]);
          goto done;
      }

      sz = os_strlcpy(fs.clustered.gfs.uuid, argv[5], sizeof(fs.clustered.gfs.uuid));
      if (sz >= sizeof(fs.clustered.gfs.uuid))
      {
          fprintf(stderr, "Invalid GFS uuid: '%s' (too long)\n", argv[5]);
          goto done;
      }

      if (to_uint64(argv[6], &fs.clustered.gfs.nb_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[6]);
          goto done;
      }

      err = fsd_fs_create_gfs(mh, &fs);
  }
  else if (strcmp(action, "dfinfo") == 0)
  {
      struct fsd_capa buf;

      if (argc != 3)
      {
          usage();
          goto done;
      }

      err = fsd_df(mh, argv[2], &buf);
      if (err == 0)
          printf("size=%"PRId64" bytes\n"
                 "used=%"PRId64" bytes\n"
                 "free=%"PRId64" bytes\n",
                 buf.size, buf.used, buf.free);
  }
  else if (strcmp(action, "resize") == 0)
  {
      uint64_t size_kb;

      if (argc != 6)
      {
          usage();
          goto done;
      }

      if (to_uint64(argv[5], &size_kb) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid new size: '%s'\n", argv[5]);
          goto done;
      }

      err = fsd_resize(mh, argv[2], argv[3], argv[4], size_kb);
  }
  else if (strcmp(action, "prepare_resize") == 0)
  {
      if (argc != 4)
      {
          usage();
          goto done;
      }

      err = fsd_prepare_resize(mh, argv[2], argv[3]);
  }
  else if (strcmp(action, "read_shm") == 0)
  {
      read_shm();
  }
  else if (strcmp(action, "add_logs") == 0)
  {
      fs_data_t fs;
      int num_logs, actual_num_logs;
      size_t sz;

      if (argc != 4)
      {
          usage();
          goto done;
      }

      COMPILE_TIME_ASSERT(sizeof("sfs") <= sizeof(fs.fstype));
      os_strlcpy(fs.fstype, "sfs", sizeof(fs.fstype));

      sz = os_strlcpy(fs.devpath, argv[2], sizeof(fs.devpath));
      if (sz >= sizeof(fs.devpath))
      {
          fprintf(stderr, "Invalid dev path: '%s' (too long)\n", argv[2]);
          goto done;
      }

      if (to_int(argv[3], &num_logs) != EXA_SUCCESS)
      {
          fprintf(stderr, "Invalid number of logs: '%s'\n", argv[3]);
          goto done;
      }

      actual_num_logs = fsd_set_gfs_logs(mh, &fs, num_logs);
      if (actual_num_logs < 0)
          err = actual_num_logs;
      else
      {
	  examsgDelMbox(mh, EXAMSG_TEST_ID);
	  printf("Number of logs after the operation: %d\n", actual_num_logs);
      }
  }
  else
      usage();

  if (err != 0)
      fprintf(stderr, "Action finished with error %d: %s\n", err,
              exa_error_msg(-err));

done:

  examsgDelMbox(mh, EXAMSG_TEST_ID);

  if (mh != NULL)
      examsgExit(mh);

  if (static_init_ok)
      examsg_static_clean(EXAMSG_STATIC_RELEASE);

  return err == 0 ? 0 : 1;
}