/* Kill and free an individual job. */ void job_free(struct job *job) { job_kill(job); SLIST_REMOVE(&all_jobs, job, job, lentry); xfree(job->cmd); if (job->freefn != NULL && job->data != NULL) job->freefn(job->data); if (job->fd != -1) close(job->fd); if (job->out != NULL) buffer_destroy(job->out); xfree(job); }
static void client_old_parse_messages(GebrCommProtocolSocket * socket, struct client *client) { GList *link; struct gebr_comm_message *message; while ((link = g_list_last(client->socket->protocol->messages)) != NULL) { message = (struct gebr_comm_message *)link->data; /* check login */ if (message->hash == gebr_comm_protocol_defs.ini_def.code_hash) { GList *arguments; GString *accounts_list = g_string_new(""); GString *queue_list = g_string_new(""); GString *display_port = g_string_new(""); /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 2)) == NULL) goto err; GString *version = g_list_nth_data(arguments, 0); GString *hostname = g_list_nth_data(arguments, 1); g_debug("Current protocol version is: %s", gebr_comm_protocol_get_version()); g_debug("Received protocol version: %s", version->str); if (strcmp(version->str, gebr_comm_protocol_get_version())) { gebr_comm_protocol_socket_oldmsg_send(client->socket, TRUE, gebr_comm_protocol_defs.err_def, 2, "protocol", gebr_comm_protocol_get_version()); goto err; } /* set client info */ client->socket->protocol->logged = TRUE; g_string_assign(client->socket->protocol->hostname, hostname->str); client->server_location = GEBR_COMM_SERVER_LOCATION_REMOTE; const gchar *server_type; if (gebrd_get_server_type() == GEBR_COMM_SERVER_TYPE_MOAB) { /* Get info from the MOAB cluster */ server_moab_read_credentials(accounts_list, queue_list); server_type = "moab"; } else server_type = "regular"; GString *mpi_flavors = g_string_new(""); g_list_foreach(gebrd->mpi_flavors, (GFunc) get_mpi_flavors, mpi_flavors); if (mpi_flavors->len > 0) mpi_flavors = g_string_erase(mpi_flavors, mpi_flavors->len-1, 1); g_debug("------------on daemon, Sending %s", mpi_flavors->str) ; const gchar *model_name; const gchar *cpu_clock; const gchar *total_memory; GebrdCpuInfo *cpuinfo = gebrd_cpu_info_new(); GebrdMemInfo *meminfo = gebrd_mem_info_new(); model_name = gebrd_cpu_info_get (cpuinfo, 0, "model name"); cpu_clock = gebrd_cpu_info_get (cpuinfo, 0, "cpu MHz"); total_memory = gebrd_mem_info_get (meminfo, "MemTotal"); gchar *ncores = g_strdup_printf("%d", gebrd_cpu_info_n_procs(cpuinfo)); gebr_comm_protocol_socket_oldmsg_send(client->socket, FALSE, gebr_comm_protocol_defs.ret_def, 11, gebrd->hostname, server_type, accounts_list->str, model_name, total_memory, gebrd->fs_lock->str, ncores, cpu_clock, gebrd_user_get_daemon_id(gebrd->user), g_get_home_dir(), mpi_flavors->str); gebrd_cpu_info_free(cpuinfo); gebrd_mem_info_free(meminfo); gebr_comm_protocol_socket_oldmsg_split_free(arguments); g_string_free(accounts_list, TRUE); g_string_free(queue_list, TRUE); g_string_free(display_port, TRUE); g_free(ncores); } else if (message->hash == gebr_comm_protocol_defs.gid_def.code_hash) { GList *arguments; /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 3)) == NULL) goto err; GString *gid = g_list_nth_data(arguments, 0); GString *cookie = g_list_nth_data(arguments, 1); GString *disp_str = g_list_nth_data(arguments, 2); guint display; if (g_strcmp0(disp_str->str, "0") == 0) display = gebr_comm_get_available_port(6010); else display = atoi(disp_str->str); display = MAX(display-6000, 0); g_hash_table_insert(gebrd->display_ports, g_strdup(gid->str), GUINT_TO_POINTER(display)); g_debug("Received gid %s with cookie %s", gid->str, cookie->str); if (cookie->len && gebrd_get_server_type() != GEBR_COMM_SERVER_TYPE_MOAB) { gebrd_message(GEBR_LOG_DEBUG, "Authorizing with system(xauth)"); gchar *tmp = g_strdup_printf(":%d", display); if (!run_xauth_command("add", tmp, cookie->str)) display = 0; g_free(tmp); } gchar *display_str = g_strdup_printf("%d", display ? display + 6000 : 0); gebrd_message(GEBR_LOG_INFO, "Sending port %s to client %s!", display_str, gid->str); gebr_comm_protocol_socket_oldmsg_send(client->socket, FALSE, gebr_comm_protocol_defs.ret_def, 2, gid->str, display_str); g_free(display_str); gebr_comm_protocol_socket_oldmsg_split_free(arguments); } else if (client->socket->protocol->logged == FALSE) { /* not logged! */ goto err; } else if (message->hash == gebr_comm_protocol_defs.qut_def.code_hash) { client_free(client); gebr_comm_message_free(message); return; } else if (message->hash == gebr_comm_protocol_defs.lst_def.code_hash) { job_list(client); } else if (message->hash == gebr_comm_protocol_defs.run_def.code_hash) { GList *arguments; GebrdJob *job; /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 9)) == NULL) goto err; GString *gid = g_list_nth_data(arguments, 0); GString *id = g_list_nth_data(arguments, 1); GString *frac = g_list_nth_data(arguments, 2); GString *numproc = g_list_nth_data(arguments, 3); GString *nice = g_list_nth_data(arguments, 4); GString *flow_xml = g_list_nth_data(arguments, 5); GString *paths = g_list_nth_data(arguments, 6); /* Moab & MPI settings */ GString *account = g_list_nth_data(arguments, 7); GString *servers_mpi = g_list_nth_data(arguments, 8); g_debug("SERVERS MPI %s", servers_mpi->str); /* try to run and send return */ job_new(&job, client, gid, id, frac, numproc, nice, flow_xml, account, paths, servers_mpi); #ifdef DEBUG gchar *env_delay = getenv("GEBRD_RUN_DELAY_SEC"); if (env_delay != NULL) sleep(atoi(env_delay)); #endif if (gebrd_get_server_type() == GEBR_COMM_SERVER_TYPE_REGULAR) { /* send job message (job is created -promoted from waiting server response- at the client) */ g_debug("RUN_DEF: run task with rid %s", id->str); job_send_clients_job_notify(job); job_run_flow(job); } else { /* ask moab to run */ job_run_flow(job); /* send job message (job is created -promoted from waiting server response- at the client) * at moab we must run the process before sending the JOB message, because at * job_run_flow moab_jid is acquired. */ job_send_clients_job_notify(job); } /* frees */ gebr_comm_protocol_socket_oldmsg_split_free(arguments); } else if (message->hash == gebr_comm_protocol_defs.rnq_def.code_hash) { } else if (message->hash == gebr_comm_protocol_defs.flw_def.code_hash) { } else if (message->hash == gebr_comm_protocol_defs.clr_def.code_hash) { GList *arguments; GString *rid; GebrdJob *job; /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 1)) == NULL) goto err; rid = g_list_nth_data(arguments, 0); job = job_find(rid); if (job != NULL) job_clear(job); /* frees */ gebr_comm_protocol_socket_oldmsg_split_free(arguments); } else if (message->hash == gebr_comm_protocol_defs.end_def.code_hash) { GList *arguments; GString *rid; GebrdJob *job; /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 1)) == NULL) goto err; rid = g_list_nth_data(arguments, 0); /* try to run and send return */ job = job_find(rid); if (job != NULL) { job_end(job); } /* frees */ gebr_comm_protocol_socket_oldmsg_split_free(arguments); } else if (message->hash == gebr_comm_protocol_defs.kil_def.code_hash) { GList *arguments; GString *rid; GebrdJob *job; /* organize message data */ if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 1)) == NULL) goto err; rid = g_list_nth_data(arguments, 0); /* try to run and send return */ job = job_find(rid); if (job != NULL) { job_kill(job); } /* frees */ gebr_comm_protocol_socket_oldmsg_split_free(arguments); } else if (message->hash == gebr_comm_protocol_defs.path_def.code_hash) { GList *arguments; if ((arguments = gebr_comm_protocol_socket_oldmsg_split(message->argument, 3)) == NULL) goto err; GString *new_path = g_list_nth_data(arguments, 0); GString *old_path = g_list_nth_data(arguments, 1); GString *opt = g_list_nth_data(arguments, 2); g_debug("new_path:%s, old_path:%s, opt:%s", new_path->str, old_path->str, opt->str); GList *new_paths= parse_comma_separated_string(new_path->str); gint option = gebr_comm_protocol_path_str_to_enum(opt->str); gint status_id = -1; gboolean flag_exists = FALSE; gboolean flag_error = FALSE; switch (option) { case GEBR_COMM_PROTOCOL_PATH_CREATE: for (GList *j = new_paths; j; j = j->next) { GString *path = j->data; if (g_file_test(path->str, G_FILE_TEST_IS_DIR)){ flag_exists = TRUE; } else if (*(path->str) && g_mkdir_with_parents(path->str, 0700)) { flag_error = TRUE; break; } if (g_access(path->str, W_OK)==-1){ flag_error = TRUE; break; } } if (flag_error) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_ERROR; else if (flag_exists) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_EXISTS; else status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_OK; break; case GEBR_COMM_PROTOCOL_PATH_RENAME: g_debug("Renaming %s to %s", old_path->str, new_path->str); gboolean dir_exist = g_file_test(new_path->str, G_FILE_TEST_IS_DIR); gboolean create_dir = g_rename(old_path->str, new_path->str) == 0; if (!dir_exist && create_dir) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_OK; else if (dir_exist && !create_dir) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_EXISTS; else if (!dir_exist && !create_dir) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_ERROR; else status_id = -1; break; case GEBR_COMM_PROTOCOL_PATH_DELETE: for (GList *j = new_paths; j; j = j->next) { GString *path = j->data; if (g_rmdir(path->str)) status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_ERROR; else status_id = GEBR_COMM_PROTOCOL_STATUS_PATH_OK; } break; default: g_warn_if_reached(); break; } g_debug("on %s, new_path:'%s', old_path:'%s', status_id: '%d'", __func__, new_path->str, old_path->str, status_id); /* frees */ gebr_comm_protocol_socket_oldmsg_split_free(arguments); gebr_comm_protocol_socket_oldmsg_send(socket, FALSE, gebr_comm_protocol_defs.ret_def, 2, gebrd->hostname, g_strdup_printf("%d", status_id)); } else if (message->hash == gebr_comm_protocol_defs.harakiri_def.code_hash) { /* Maestro wants me killed */ g_debug("Harakiri"); gebrd_quit(); } else { /* unknown message! */ goto err; } gebr_comm_message_free(message); client->socket->protocol->messages = g_list_delete_link(client->socket->protocol->messages, link); } return; err: gebr_comm_message_free(message); client->socket->protocol->messages = g_list_delete_link(client->socket->protocol->messages, link); client_disconnected(socket, client); }
/* * Usage: exit */ void builtin_exit() { job_kill(); _exit(0); }