PadicoTM

Documentation

« back to PM2 home.
console-mod.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2024 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
35#include <stdio.h>
36#include <unistd.h>
37#include <sys/fcntl.h>
38#include <Padico/Puk.h>
39#include <Padico/PadicoTM.h>
40#include <Padico/Module.h>
41
42static int padico_console_init(void);
43static int padico_console_run(int argc, char**argv);
45
47
48static void console_loop(void);
49static int done = 0;
50static int running = 0;
51static char*console_name;
53
54static int padico_console_init(void)
55{
56 int rc;
57 if(isatty(0))
58 {
60 rc = 0;
61 }
62 else
63 {
64 padico_warning("stdin is not a tty-- abort.\n");
66 rc = -1;
67 }
68 return rc;
69}
70
71static int padico_console_run(int argc, char**argv)
72{
73 padico_trace("run()\n");
74 if(console_name != NULL)
75 {
76 padico_print("Starting Padico console on %s\n", console_name);
77 /* fcntl(fd, F_SETFD, O_NONBLOCK); */
78 console = fopen(console_name, "r+");
80 if(console == NULL)
81 {
82 padico_warning("open error\n");
83 return -1;
84 }
85 running = 1;
87 }
88 else
89 {
90 padico_warning("stdin is not a tty\n");
91 }
92 return 0;
93}
94
96{
97 padico_trace("finalize() join thread\n");
98 done = 1;
99 if(running)
100 {
102 padico_print("close on %s\n", console_name);
103 }
104 running = 0;
105 padico_trace("finalize() ok\n");
106}
107
108#define TAB_SIZE 4096
109
110static void console_loop(void)
111{
112 char cmd[TAB_SIZE];
113 char*c;
115
116 fprintf(console, "# Welcome in %s console\n", PADICOTM_VERSION_STRING);
117 fprintf(console, "# ok/console %s\n", padico_hostname());
118 while(!done)
119 {
120 fprintf(console, "# PadicoConsole > ");
122 c = fgets(cmd, TAB_SIZE, console);
123 if(feof(console))
124 {
125 fprintf(console, "\n# ok/EOF\n");
126 done = 1;
127 }
128 else if(c == NULL)
129 {
130 continue;
131 }
132 else if(cmd[0] == '\n')
133 {
134 continue;
135 }
136 else if(cmd[0] == '<')
137 {
138 /* TODO: it should be converted into a PADICO_TM_CMDTASK */
139 struct puk_parse_entity_s pe;
141 rc = pe.rc;
142 }
143 else if(strncasecmp(cmd, "help\n", TAB_SIZE) == 0)
144 {
145 rc = padico_rc_msg("Commands are: load run unload start restart exit lsmod lsaction lstopo file inspectmod");
146 }
147 else if(strncasecmp(cmd, "xml\n", TAB_SIZE) == 0)
148 {
149 char tab[TAB_SIZE];
150 struct puk_parse_entity_s pe;
151 fprintf(console, "# xml? ");
154 tab[strlen(tab)-1] = 0;
156 rc = pe.rc;
157 }
158 else if(strncasecmp(cmd, "lstopo\n", TAB_SIZE) == 0)
159 {
160 const char cmd[] = "<lstopo/>";
162 rc = pe.rc;
163 }
164 else if(strncasecmp(cmd, "lsmod\n", TAB_SIZE) == 0)
165 {
166 rc = puk_mod_lsmod();
167 }
168 else if(strncasecmp(cmd, "lsaction\n", TAB_SIZE) == 0)
169 {
171 }
172 else if(strncasecmp(cmd, "inspectmod\n", TAB_SIZE) == 0)
173 {
174 char tab[TAB_SIZE];
175 fprintf(console, "# inspectmod? ");
178 tab[strlen(tab)-1] = 0;
180 }
181 else if(strncasecmp(cmd, "load\n", TAB_SIZE) == 0)
182 {
183 char tab[TAB_SIZE];
184 fprintf(console, "# Load? ");
187 tab[strlen(tab)-1] = 0;
189 }
190 else if(strncasecmp(cmd, "run\n", TAB_SIZE) == 0)
191 {
192 char tab[TAB_SIZE];
193 fprintf(console, "# Run? ");
196 tab[strlen(tab)-1] = 0;
198 }
199 else if(strncasecmp(cmd, "unload\n", TAB_SIZE) == 0)
200 {
201 char tab[TAB_SIZE];
202 fprintf(console, "# Unload? ");
205 tab[strlen(tab)-1] = 0;
207 }
208 else if(strncasecmp(cmd, "start\n", TAB_SIZE) == 0)
209 {
210 char tab[TAB_SIZE];
211 fprintf(console, "# Start? ");
214 tab[strlen(tab)-1] = 0;
218 }
219 else if(strncasecmp(cmd, "restart\n", TAB_SIZE) == 0)
220 {
221 char tab[TAB_SIZE];
222 fprintf(console, "# Restart? ");
225 tab[strlen(tab)-1] = 0;
231 }
232 else if(strncasecmp(cmd, "file\n", TAB_SIZE) == 0)
233 {
234 char tab[TAB_SIZE];
235 fprintf(console, "# File? ");
238 tab[strlen(tab)-1] = 0;
239 padico_task_t t = padico_malloc(sizeof(struct padico_task_s));
240 t->task_req = NULL;
241 t->kind = PADICO_TM_TASK_FILE;
242 t->tinfo.ftask.file = padico_strdup(tab);
243 padico_tm_task_enqueue(t, "task file");
244 }
245 else if(strncasecmp(cmd, "exit\n", TAB_SIZE) == 0)
246 {
247 done = 1;
249 rc = NULL;
250 }
251 else
252 {
253 rc = padico_rc_error("unknown command. Type 'help' for help.");
254 }
255 if(rc == NULL)
256 {
257 fprintf(stderr, "ok/0\n");
258 }
259 else if(rc->rc)
260 {
261 fprintf(stderr, "err/%s\n", padico_string_get(rc->msg));
262 }
263 else if(rc->msg)
264 {
265 fprintf(stderr, "ok/%s\n", padico_string_get(rc->msg));
266 }
267 if(rc)
268 {
270 rc = NULL;
271 }
273 }
274 /* padico_tm_mod_action(PADICO_TM_MOD_UNLOAD, padico_module_self_name()); */
275}
return NULL
Definition Shm.h:88
static char * console_name
Definition console-mod.c:51
static int running
Definition console-mod.c:50
static void console_loop(void)
static int done
Definition console-mod.c:49
static FILE * console
Definition console-mod.c:52
#define TAB_SIZE
static int padico_console_init(void)
Definition console-mod.c:54
void padico_console_finalize(void)
Definition console-mod.c:95
static int padico_console_run(int argc, char **argv)
Definition console-mod.c:71
#define padico_tm_task_enqueue(TASK, NAME)
Definition PadicoTM.h:262
void padico_tm_exit(void)
padico_rc_t padico_tm_mod_action_args(enum padico_mtask_kind_e kind, const char *mod_name, int argc, char **argv)
Definition tm-mod.c:46
padico_rc_t rc
Definition PadicoTM.h:146
static padico_rc_t padico_tm_mod_action(enum padico_mtask_kind_e kind, const char *mod_name)
Definition PadicoTM.h:254
@ PADICO_TM_MOD_LOAD
Definition PadicoTM.h:200
@ PADICO_TM_MOD_RUN
Definition PadicoTM.h:202
@ PADICO_TM_MOD_UNLOAD
Definition PadicoTM.h:201