Beispiel #1
0
void screenshot_clicked(GtkWidget* widget)
{
    /* Launch Report a problem*/
    launch_cmd(REPORT_CMD, "kano-feedback");
    /* Play sound */
    launch_cmd(SOUND_CMD, NULL);
}
Beispiel #2
0
void knowledge_clicked(GtkWidget* widget)
{
    /* Launch help center */
    launch_cmd(HELP_CMD, "kano-help-launcher");
    /* Play sound */
    launch_cmd(SOUND_CMD, NULL);
}
Beispiel #3
0
void contact_clicked(GtkWidget* widget)
{
    /* Launch Contact Us*/
    launch_cmd(CONTACT_CMD, "kano-feedback");
    /* Play sound */
    launch_cmd(SOUND_CMD, NULL);
}
Beispiel #4
0
void settings_clicked(GtkWidget* widget, const char* state)
{
    /* Launch command sudo kano-settings state */
    char cmd[100];
    strcpy(cmd, SETTINGS_CMD);
    strcat(cmd, state);
    launch_cmd(cmd, "kano-settings");
    /* Play sound */
    launch_cmd(SOUND_CMD, NULL);
}
Beispiel #5
0
int	cmd_client(t_client *client, t_kernel *kernel,
		   t_buffer *buff_node)
{
  char	*buffer;

  buffer = read_on(client->fd, buff_node);
  if (buffer == NULL)
    return (-1);
  else if (buffer == (void *)2)
    {
      printf("[\033[31;1mOK\033[0m] Deconnection from %s\n", client->ip);
      pop_client(client->fd, kernel);
      return (1);
    }
  printf("[\033[32;1mClient %s\033[0m] msg : [%s]\n", client->ip, buffer);
  return (launch_cmd(buffer, client, kernel));
}
Beispiel #6
0
bg_task launch_background_cmd(int task_id, std::vector<std::string> args)
{
	timeval t;
	gettimeofday(&t, nullptr);

	int pipefd[2];
	if (0 == pipe(pipefd))
	{
		pid_t watcher_pid = fork();
		switch (watcher_pid)
		{
			case -1: // Error
			{
				std::cerr << "Error on fork(): " << strerror(errno) << "\n";
				return bg_task{-2, process_info{-1, t}, process_info{}};
			} break;

			case 0: // Child process
			{
				close(pipefd[0]); // Close read end

				auto info = launch_cmd(args);
				write(pipefd[1], &info, sizeof(process_info));
				wait_cmd(info);

				std::exit(EXIT_SUCCESS);
			} break;

			default: // Parent process
			{
				close(pipefd[1]); // Close write end

				process_info info;
				read(pipefd[0], &info, sizeof(process_info));

				return bg_task{task_id, process_info{watcher_pid, t}, info};
			} break;
		}
	}
	else
	{
		std::cerr << "Error on pipe(): " << strerror(errno) << "\n";
		return bg_task{-1, process_info{-1, t}, process_info{}};
	}
}
Beispiel #7
0
int main(int /* argc */, char* /* argv */[])
{
	auto bg_tasks = std::map<int, bg_task>();

	timeval start;
	gettimeofday(&start, nullptr);

	int next_task_id = 0;

	bool quit = false;
	while (not quit)
	{
		std::string line;
		std::cout << get_current_dir_name() << "> ";
		std::cout.flush();
		if (not std::getline(std::cin, line) || line == "exit")
		{
			std::cout << std::endl;
			quit = true;
		}
		else
		{
			auto is_whitespace = [](char c){
				return std::isspace(c) != 0;
			};
			auto begin = std::find_if_not(line.begin(), line.end(), is_whitespace);
			auto end = line.end();
			auto result = begin;
			std::vector<std::string> args;
			while (begin != end)
			{
				result = std::find(begin, end, ' ');
				args.emplace_back(begin, result);
				begin = std::find_if_not(result, end, is_whitespace);
			}

			if (not args.empty())
			{
				if (args.back() == "&")
				{
					args.pop_back();
					auto task = launch_background_cmd(next_task_id++, args);
					std::cout << task << std::endl;
					bg_tasks[task.exec_proc.id] = task;
				}
				else if (args[0] == "cd")
				{
					cd(args[1]);
				}
				else if (args[0] == "aptaches")
				{
					check_processes(bg_tasks);
					// for (std::map<int, bg_task>::const_iterator it=bg_tasks.begin(); it!=bg_tasks.end(); ++it) {
					for (auto pair : bg_tasks)
					{
						std::cout << pair.second << std::endl;
					}
				}
				else
				{
					wait_cmd(launch_cmd(args));
				}
			}
		}
	}
	/* Kill everything in bg_tasks */
	check_processes(bg_tasks);
	for (auto pair : bg_tasks)
	{
		kill(pair.second.exec_proc.id, SIGTERM);
	}
}