home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / distributed-c-2.1 / part15 < prev    next >
Text File  |  1993-12-22  |  75KB  |  1,745 lines

  1. Newsgroups: comp.sources.unix
  2. From: pleierc@informatik.tu-muenchen.de (Christoph Pleier)
  3. Subject: v27i189: distributed-c-2.1 - Distributed C Development Environment, V2.1, Part15/18
  4. References: <1.756634932.28500@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: pleierc@informatik.tu-muenchen.de (Christoph Pleier)
  9. Posting-Number: Volume 27, Issue 189
  10. Archive-Name: distributed-c-2.1/part15
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 15 (of 18)."
  19. # Contents:  dcc/attr_decl.c lib/creation.c
  20. # Wrapped by vixie@gw.home.vix.com on Thu Dec 23 00:12:06 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'dcc/attr_decl.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'dcc/attr_decl.c'\"
  24. else
  25. echo shar: Extracting \"'dcc/attr_decl.c'\" \(35350 characters\)
  26. sed "s/^X//" >'dcc/attr_decl.c' <<'END_OF_FILE'
  27. X/***************************************************************************
  28. X *                                                                         *
  29. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  30. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  31. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  32. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  33. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  34. X *                                                                         *
  35. X *              A compiler for distributed programming with C              *
  36. X *                                                                         *
  37. X *                          a t t r _ d e c l . c                          *
  38. X *                                                                         *
  39. X *                            Package : Compiler                           *
  40. X *                            Version : 1.0                                *
  41. X *                       CreationDate : 04.09.91                           *
  42. X *                         LastUpDate : 08.11.91                           *
  43. X *                                                                         *
  44. X * All routines used for generating and managing attributes needed for     *
  45. X * handling structure and type definitions.                                *
  46. X *                                                                         *
  47. X *               Copyright (C) 1991-1994 by Christoph Pleier               *
  48. X *                          All rights reserved!                           *
  49. X ***************************************************************************/
  50. X
  51. X/*
  52. X * This file is part of the Distributed C Development Environment (DCDE).
  53. X * DCDE is free software; you can redistribute it and/or modify
  54. X * it under the terms written in the README-file. 
  55. X * DCDE is distributed in the hope that it will be useful,
  56. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  58. X * See the file README for more details.
  59. X */
  60. X
  61. X#include <stdio.h>
  62. X#include "config.h"
  63. X#include "extern.h"
  64. X#include "functions.h"
  65. X
  66. X/* NOTE:
  67. X * During parsing of declarations an internal tree is dynamically generated
  68. X * to store the information. Later this tree will only be converted to a string
  69. X * or will be used for generating special data conversion routines and for
  70. X * some sematic checks.
  71. X * The structure of such trees is modelled directly on the syntax grammar (see
  72. X * dcc.y). The appropriate data types are specified in config.h.
  73. X */
  74. X
  75. X/******************************************************************************
  76. X * gen_type_specifier_attr()                                                  *
  77. X *                                                                            *
  78. X * Allocates memory for a type specifier attribute and initializes it.        *
  79. X *                                                                            *
  80. X * Return values: pointer to new created attribute upon success /             *
  81. X *                NULL during error handling                                  *
  82. X ******************************************************************************/
  83. XTS_ATTR *
  84. Xgen_type_specifier_attr(t_elem, t_enum, t_struct, t_ident)
  85. Xint        t_elem;
  86. XES_ATTR   *t_enum;
  87. XSUS_ATTR  *t_struct;
  88. XSYMBTABEL *t_ident;
  89. X{
  90. X    register TS_ATTR *ptr;
  91. X
  92. X    if (errflag)    /* error handling! */
  93. X    return(NULL);
  94. X#ifdef STRUCTDEBUG
  95. X    fprintf(debugfile, "[type] ***** gen_type_specifier_attr():\n");
  96. X    fprintf(debugfile, "[type]       params: t_elem = %d, t_enum = %d\n",
  97. X        t_elem, t_enum);
  98. X    fprintf(debugfile, "[type]               t_struct = %d, t_ident = %d (%s)\n",
  99. X        t_struct, t_ident, (t_ident) ? t_ident->name : "null");
  100. X#endif /* STRUCTDEBUG /**/
  101. X    ptr = (TS_ATTR *) Malloc(sizeof(TS_ATTR));
  102. X#ifdef STRUCTDEBUG
  103. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  104. X#endif /* STRUCTDEBUG /**/
  105. X    ptr->type = t_elem;
  106. X    switch(t_elem) {
  107. X    case TS_ATTR_VOID:
  108. X        ptr->type = choose_void_type();
  109. X    break;
  110. X    case TS_ATTR_CHAR:
  111. X    case TS_ATTR_SHORT:
  112. X    case TS_ATTR_INT:
  113. X    case TS_ATTR_LONG:
  114. X    case TS_ATTR_FLOAT:
  115. X    case TS_ATTR_DOUBLE:
  116. X    case TS_ATTR_SIGNED:
  117. X    case TS_ATTR_UNSIGNED:
  118. X    break;
  119. X    case TS_ATTR_PROCESS:
  120. X    ptr->info.process = t_ident;
  121. X    break;
  122. X    case TS_ATTR_ENUM:
  123. X    ptr->info.enuminfo = t_enum;
  124. X    break;
  125. X    case TS_ATTR_STRUCT:
  126. X    ptr->info.structinfo = t_struct;
  127. X    break;
  128. X    case TS_ATTR_TYPENAME:
  129. X    ptr->info.typedefname = t_ident;
  130. X    break;
  131. X    default:
  132. X    Panic("unknown TS_ATTR type in gen_type_specifier_attr()");
  133. X    } /* switch */
  134. X    return(ptr);
  135. X} /* gen_type_specifier_attr */
  136. X
  137. X/******************************************************************************
  138. X * gen_storage_class_spec_attr()                                              *
  139. X *                                                                            *
  140. X * Allocates memory for a storage class specifier attribute and initializes   *
  141. X * it.                                                                        *
  142. X *                                                                            *
  143. X * Return values: pointer to new created attribute upon success /             *
  144. X *                NULL during error handling                                  *
  145. X ******************************************************************************/
  146. XSCS_ATTR *
  147. Xgen_storage_class_spec_attr(type)
  148. Xchar type;
  149. X{
  150. X    register SCS_ATTR *ptr;
  151. X
  152. X    if (errflag)    /* error handling! */
  153. X    return(NULL);
  154. X#ifdef STRUCTDEBUG
  155. X    fprintf(debugfile, "[type] ***** gen_storage_class_attr():\n");
  156. X    fprintf(debugfile, "[type]       params: type = %d\n", type);
  157. X#endif /* STRUCTDEBUG /**/
  158. X    ptr = (SCS_ATTR *) Malloc(sizeof(SCS_ATTR));
  159. X#ifdef STRUCTDEBUG
  160. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  161. X#endif /* STRUCTDEBUG /**/
  162. X    switch(type) {
  163. X    case SCS_ATTR_AUTO:
  164. X    case SCS_ATTR_REGISTER:
  165. X    case SCS_ATTR_STATIC:
  166. X    case SCS_ATTR_EXTERN:
  167. X    case SCS_ATTR_TYPEDEF:
  168. X    ptr->type = type;
  169. X    break;
  170. X    default:
  171. X    Panic("unknown type qualifier in gen_storage_class_spec_attr()");
  172. X    } /* switch */
  173. X    return(ptr);
  174. X} /* gen_storage_class_spec_attr */
  175. X
  176. X/******************************************************************************
  177. X * gen_type_qualifier_attr()                                                  *
  178. X *                                                                            *
  179. X * Allocates memory for a type qualifier attribute and initializes it.        *
  180. X *                                                                            *
  181. X * Return values: pointer to new created attribute upon success /             *
  182. X *                NULL during error handling                                  *
  183. X ******************************************************************************/
  184. XTQ_ATTR *
  185. Xgen_type_qualifier_attr(type)
  186. Xchar type;
  187. X{
  188. X    register TQ_ATTR *ptr;
  189. X
  190. X    if (errflag)    /* error handling! */
  191. X    return(NULL);
  192. X#ifdef STRUCTDEBUG
  193. X    fprintf(debugfile, "[type] ***** gen_type_qualifier_attr():\n");
  194. X    fprintf(debugfile, "[type]       params: type = %d\n", type);
  195. X#endif /* STRUCTDEBUG /**/
  196. X    ptr = (TQ_ATTR *) Malloc(sizeof(TQ_ATTR));
  197. X#ifdef STRUCTDEBUG
  198. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  199. X#endif /* STRUCTDEBUG /**/
  200. X    switch(type) {
  201. X    case TQ_ATTR_CONST:
  202. X    case TQ_ATTR_VOLATILE:
  203. X    ptr->type = type;
  204. X    break;
  205. X    default:
  206. X    Panic("unknown type qualifier in gen_type_qualifier_attr()");
  207. X    } /* switch */
  208. X    return(ptr);
  209. X} /* gen_type_qualifier_attr */
  210. X
  211. X/******************************************************************************
  212. X * gen_struct_or_union_attr()                                                 *
  213. X *                                                                            *
  214. X * Allocates memory for a struct or union attribute and initializes it.       *
  215. X *                                                                            *
  216. X * Return values: pointer to new created attribute upon success /             *
  217. X *                NULL during error handling                                  *
  218. X ******************************************************************************/
  219. XSU_ATTR *
  220. Xgen_struct_or_union_attr(type)
  221. Xchar type;
  222. X{
  223. X    register SU_ATTR *ptr;
  224. X
  225. X    if (errflag)    /* error handling! */
  226. X    return(NULL);
  227. X#ifdef STRUCTDEBUG
  228. X    fprintf(debugfile, "[type] ***** gen_struct_or_union_attr():\n");
  229. X    fprintf(debugfile, "[type]       params: type = %d\n", type);
  230. X#endif /* STRUCTDEBUG /**/
  231. X    ptr = (SU_ATTR *) Malloc(sizeof(SU_ATTR));
  232. X#ifdef STRUCTDEBUG
  233. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  234. X#endif /* STRUCTDEBUG /**/
  235. X    switch(type) {
  236. X    case SU_ATTR_STRUCT:
  237. X    case SU_ATTR_UNION:
  238. X    ptr->type = type;
  239. X    break;
  240. X    default:
  241. X    Panic("unknown type qualifier in gen_struct_or_union_attr()");
  242. X    } /* switch */
  243. X    return(ptr);
  244. X} /* gen_struct_or_union_attr */
  245. X
  246. X/******************************************************************************
  247. X * gen_struct_or_union_spec_attr()                                            *
  248. X *                                                                            *
  249. X * Allocates memory for a struct or union specifier attribute and initializes *
  250. X * it.                                                                        *
  251. X *                                                                            *
  252. X * Return values: pointer to new created attribute upon success /             *
  253. X *                NULL during error handling                                  *
  254. X ******************************************************************************/
  255. XSUS_ATTR *
  256. Xgen_struct_or_union_spec_attr(struct_or_union, tag, struct_declaration_list)
  257. XSU_ATTR   *struct_or_union;
  258. XSYMBTABEL *tag;
  259. XSTL_ATTR  *struct_declaration_list;
  260. X{
  261. X    register SUS_ATTR *ptr;
  262. X
  263. X#ifdef STRUCTDEBUG
  264. X    fprintf(debugfile, "[type] ***** gen_struct_or_union_spec_attr():\n");
  265. X    fprintf(debugfile, "[type]       params: struct_or_union = %d\n",
  266. X        struct_or_union);
  267. X    fprintf(debugfile, "[type]               tag = %d\n", tag);
  268. X    fprintf(debugfile, "[type]               struct_declaration_list = %d\n",
  269. X        struct_declaration_list);
  270. X#endif /* STRUCTDEBUG /**/
  271. X    ptr = (SUS_ATTR *) Malloc(sizeof(SUS_ATTR));
  272. X#ifdef STRUCTDEBUG
  273. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  274. X#endif /* STRUCTDEBUG /**/
  275. X    ptr->struct_or_union  = struct_or_union;
  276. X    ptr->tag              = tag;
  277. X    ptr->struct_decl_list = struct_declaration_list;
  278. X    return(ptr);
  279. X} /* gen_struct_or_union_spec_attr */
  280. X
  281. X/******************************************************************************
  282. X * gen_enum_specifier_attr()                                                  *
  283. X *                                                                            *
  284. X * Allocates memory for an enum specifier attribute and initializes it.       *
  285. X *                                                                            *
  286. X * Return values: pointer to new created attribute upon success /             *
  287. X *                NULL during error handling                                  *
  288. X ******************************************************************************/
  289. XES_ATTR *
  290. Xgen_enum_specifier_attr(codestr)
  291. Xchar *codestr;
  292. X{
  293. X    register ES_ATTR *ptr;
  294. X
  295. X#ifdef STRUCTDEBUG
  296. X    fprintf(debugfile, "[type] ***** gen_enum_specifier_attr():\n");
  297. X    fprintf(debugfile, "[type]       params: codestr = %s\n", codestr);
  298. X#endif /* STRUCTDEBUG /**/
  299. X    ptr = (ES_ATTR *) Malloc(sizeof(ES_ATTR));
  300. X#ifdef STRUCTDEBUG
  301. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  302. X#endif /* STRUCTDEBUG /**/
  303. X    ptr->codestr = codestr;
  304. X    return(ptr);
  305. X} /* gen_enum_specifier_attr */
  306. X
  307. X/******************************************************************************
  308. X * gen_struct_declaration_attr()                                              *
  309. X *                                                                            *
  310. X * Allocates memory for a struct declaration attribute and initializes it.    *
  311. X *                                                                            *
  312. X * Return values: pointer to new created attribute upon success /             *
  313. X *                NULL during error handling                                  *
  314. X ******************************************************************************/
  315. XST_ATTR *
  316. Xgen_struct_declaration_attr(spec_qual_list, struct_decl_list)
  317. XSQL_ATTR *spec_qual_list;
  318. XSDL_ATTR *struct_decl_list;
  319. X{
  320. X    register ST_ATTR *ptr;
  321. X
  322. X#ifdef STRUCTDEBUG
  323. X    fprintf(debugfile, "[type] ***** gen_struct_declaration_attr():\n");
  324. X    fprintf(debugfile, "[type]       params: spec_qual_list = %d\n",
  325. X        spec_qual_list);
  326. X    fprintf(debugfile, "[type]               struct_decl_list = %d\n",
  327. X        struct_decl_list);
  328. X#endif /* STRUCTDEBUG /**/
  329. X    ptr = (ST_ATTR *) Malloc(sizeof(ST_ATTR));
  330. X#ifdef STRUCTDEBUG
  331. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  332. X#endif /* STRUCTDEBUG /**/
  333. X    ptr->spec_qual_list   = spec_qual_list;
  334. X    ptr->struct_decl_list = struct_decl_list;
  335. X    return(ptr);
  336. X} /* gen_struct_declaration_attr */
  337. X
  338. X/******************************************************************************
  339. X * gen_spec_qual_list_attr()                                                  *
  340. X *                                                                            *
  341. X * Allocates memory for a specifier qualifier list attribute and initializes  *
  342. X * it.                                                                        *
  343. X *                                                                            *
  344. X * Return values: pointer to new created attribute upon success /             *
  345. X *                NULL during error handling                                  *
  346. X ******************************************************************************/
  347. XSQL_ATTR *
  348. Xgen_spec_qual_list_attr(type_specifier, type_qualifier)
  349. XTS_ATTR *type_specifier;
  350. XTQ_ATTR *type_qualifier;
  351. X{
  352. X    register SQL_ATTR *ptr;
  353. X
  354. X#ifdef STRUCTDEBUG
  355. X    fprintf(debugfile, "[type] ***** gen_spec_qual_list_attr():\n");
  356. X    fprintf(debugfile, "[type]       params: type_specifier = %d\n",
  357. X        type_specifier);
  358. X    fprintf(debugfile, "[type]               type_qualifier = %d\n",
  359. X        type_qualifier);
  360. X#endif /* STRUCTDEBUG /**/
  361. X    ptr = (SQL_ATTR *) Malloc(sizeof(SQL_ATTR));
  362. X#ifdef STRUCTDEBUG
  363. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  364. X#endif /* STRUCTDEBUG /**/
  365. X    if (type_specifier) {
  366. X    ptr->type = SQL_ATTR_SPECIFIER;
  367. X    ptr->info.type_specifier = type_specifier;
  368. X    } else {
  369. X    ptr->type = SQL_ATTR_QUALIFIER;
  370. X    ptr->info.type_qualifier = type_qualifier;
  371. X    }
  372. X    ptr->sq_list = NULL;
  373. X    return(ptr);
  374. X} /* gen_spec_qual_list_attr */
  375. X
  376. X/******************************************************************************
  377. X * gen_struct_declarator_list_attr()                                          *
  378. X *                                                                            *
  379. X * Allocates memory for a struct declarator list attribute and initializes it.*
  380. X *                                                                            *
  381. X * Return values: pointer to new created attribute upon success /             *
  382. X *                NULL during error handling                                  *
  383. X ******************************************************************************/
  384. XSDL_ATTR *
  385. Xgen_struct_declarator_list_attr(struct_declarator)
  386. XSD_ATTR *struct_declarator;
  387. X{
  388. X    register SDL_ATTR *ptr;
  389. X
  390. X#ifdef STRUCTDEBUG
  391. X    fprintf(debugfile, "[type] ***** gen_struct_declarator_list_attr():\n");
  392. X    fprintf(debugfile, "[type]       params: struct_declarator = %d\n",
  393. X        struct_declarator);
  394. X#endif /* STRUCTDEBUG /**/
  395. X    ptr = (SDL_ATTR *) Malloc(sizeof(SDL_ATTR));
  396. X#ifdef STRUCTDEBUG
  397. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  398. X#endif /* STRUCTDEBUG /**/
  399. X    ptr->struct_declarator = struct_declarator;
  400. X    ptr->sd_list = NULL;
  401. X    return(ptr);
  402. X} /* gen_struct_declarator_list_attr */
  403. X
  404. X/******************************************************************************
  405. X * gen_stru_declaration_list_attr()                                           *
  406. X *                                                                            *
  407. X * Allocates memory for a struct declaration list attribute and initializes   *
  408. X * it.                                                                        *
  409. X *                                                                            *
  410. X * Return values: pointer to new created attribute upon success /             *
  411. X *                NULL during error handling                                  *
  412. X ******************************************************************************/
  413. XSTL_ATTR *
  414. Xgen_stru_declaration_list_attr(struct_declaration)
  415. XST_ATTR *struct_declaration;
  416. X{
  417. X    register STL_ATTR *ptr;
  418. X
  419. X#ifdef STRUCTDEBUG
  420. X    fprintf(debugfile, "[type] ***** gen_stru_declaration_list_attr():\n");
  421. X    fprintf(debugfile, "[type]       params: struct_declaration = %d\n",
  422. X        struct_declaration);
  423. X#endif /* STRUCTDEBUG /**/
  424. X    ptr = (STL_ATTR *) Malloc(sizeof(STL_ATTR));
  425. X#ifdef STRUCTDEBUG
  426. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  427. X#endif /* STRUCTDEBUG /**/
  428. X    ptr->struct_decl = struct_declaration;
  429. X    ptr->st_list = NULL;
  430. X    return(ptr);
  431. X} /* gen_stru_declaration_list_attr */
  432. X
  433. X/******************************************************************************
  434. X * gen_struct_declarator_attr()                                               *
  435. X *                                                                            *
  436. X * Allocates memory for a struct declarator attribute and initializes it.     *
  437. X *                                                                            *
  438. X * Return values: pointer to new created attribute upon success /             *
  439. X *                NULL during error handling                                  *
  440. X ******************************************************************************/
  441. XSD_ATTR *
  442. Xgen_struct_declarator_attr(declarator, const_expr)
  443. XD_ATTR *declarator;
  444. Xchar   *const_expr;
  445. X{
  446. X    register SD_ATTR *ptr;
  447. X
  448. X#ifdef STRUCTDEBUG
  449. X    fprintf(debugfile, "[type] ***** gen_struct_declarator_attr():\n");
  450. X    fprintf(debugfile, "[type]       params: declarator = %d\n", declarator);
  451. X    fprintf(debugfile, "[type]               const_expr = %s\n", const_expr);
  452. X#endif /* STRUCTDEBUG /**/
  453. X    ptr = (SD_ATTR *) Malloc(sizeof(SD_ATTR));
  454. X#ifdef STRUCTDEBUG
  455. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  456. X#endif /* STRUCTDEBUG /**/
  457. X    ptr->decl = declarator;
  458. X    ptr->const_expr = const_expr;
  459. X    return(ptr);
  460. X} /* gen_struct_declarator_attr */
  461. X
  462. X/******************************************************************************
  463. X * gen_declarator_attr()                                                      *
  464. X *                                                                            *
  465. X * Allocates memory for a declarator attribute and initializes it.            *
  466. X *                                                                            *
  467. X * Return values: pointer to new created attribute upon success /             *
  468. X *                NULL during error handling                                  *
  469. X ******************************************************************************/
  470. XD_ATTR *
  471. Xgen_declarator_attr(pointer, direct_decl)
  472. XP_ATTR  *pointer;
  473. XDD_ATTR *direct_decl;
  474. X{
  475. X    register D_ATTR *ptr;
  476. X
  477. X#ifdef STRUCTDEBUG
  478. X    fprintf(debugfile, "[type] ***** gen_declarator_attr():\n");
  479. X    fprintf(debugfile, "[type]       params: pointer = %d\n", pointer);
  480. X    fprintf(debugfile, "[type]               direct_decl = %d\n", direct_decl);
  481. X#endif /* STRUCTDEBUG /**/
  482. X    ptr = (D_ATTR *) Malloc(sizeof(D_ATTR));
  483. X#ifdef STRUCTDEBUG
  484. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  485. X#endif /* STRUCTDEBUG /**/
  486. X    ptr->pointer = pointer;
  487. X    ptr->direct_decl = direct_decl;
  488. X    return(ptr);
  489. X} /* gen_declarator_attr */
  490. X
  491. X/******************************************************************************
  492. X * gen_direct_decl_attr()                                                     *
  493. X *                                                                            *
  494. X * Allocates memory for a direct declarator attribute and initializes it.     *
  495. X *                                                                            *
  496. X * Return values: pointer to new created attribute upon success /             *
  497. X *                NULL during error handling                                  *
  498. X ******************************************************************************/
  499. XDD_ATTR *
  500. Xgen_direct_decl_attr(type, ident, declarator, direct_decl, str)
  501. Xchar       type;
  502. XSYMBTABEL *ident;
  503. XD_ATTR    *declarator;
  504. XDD_ATTR   *direct_decl;
  505. Xchar      *str;
  506. X{
  507. X    register DD_ATTR *ptr;
  508. X
  509. X#ifdef STRUCTDEBUG
  510. X    fprintf(debugfile, "[type] ***** gen_direct_decl_attr():\n");
  511. X    fprintf(debugfile, "[type]       params: ident = %s\n", 
  512. X    (ident) ? ident->name : "null");
  513. X    fprintf(debugfile, "[type]               declarator = %d\n", declarator);
  514. X#endif /* STRUCTDEBUG /**/
  515. X    ptr = (DD_ATTR *) Malloc(sizeof(DD_ATTR));
  516. X#ifdef STRUCTDEBUG
  517. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  518. X#endif /* STRUCTDEBUG /**/
  519. X    ptr->type = type;
  520. X    switch(type) {
  521. X    case DD_ATTR_IDENT:
  522. X            ptr->ident = ident;
  523. X        break;
  524. X    case DD_ATTR_BRACED:
  525. X        ptr->info.declarator = declarator;
  526. X        break;
  527. X    case DD_ATTR_ARRAY:
  528. X    case DD_ATTR_FUNC:
  529. X        ptr->info.comp.direct_decl = direct_decl;
  530. X        ptr->info.comp.spec_str    = str;
  531. X        break;
  532. X    default:
  533. X        Panic("unknown DD_ATTR type in gen_direct_decl_attr()");
  534. X    } /* switch */
  535. X    return(ptr);
  536. X} /* gen_direct_decl_attr */
  537. X
  538. X/******************************************************************************
  539. X * gen_pointer_attr()                                                         *
  540. X *                                                                            *
  541. X * Allocates memory for a pointer attribute and initializes it.               *
  542. X *                                                                            *
  543. X * Return values: pointer to new created attribute upon success /             *
  544. X *                NULL during error handling                                  *
  545. X ******************************************************************************/
  546. XP_ATTR *
  547. Xgen_pointer_attr(type, quali_list, pointer)
  548. Xint       type;
  549. XTQL_ATTR *quali_list;
  550. XP_ATTR   *pointer;
  551. X{
  552. X    register P_ATTR *ptr;
  553. X
  554. X#ifdef STRUCTDEBUG
  555. X    fprintf(debugfile, "[type] ***** gen_pointer_attr():\n");
  556. X    fprintf(debugfile, "[type]       params: type = %d\n", type);
  557. X#endif /* STRUCTDEBUG /**/
  558. X    ptr = (P_ATTR *) Malloc(sizeof(P_ATTR));
  559. X#ifdef STRUCTDEBUG
  560. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  561. X#endif /* STRUCTDEBUG /**/
  562. X    ptr->type = type;
  563. X    ptr->quali_list = quali_list;
  564. X    ptr->pointer = pointer;
  565. X    return(ptr);
  566. X} /* gen_pointer_attr */
  567. X
  568. X/******************************************************************************
  569. X * gen_type_qualifier_list_attr()                                             *
  570. X *                                                                            *
  571. X * Allocates memory for a type qualifier list attribute and initializes it.   *
  572. X *                                                                            *
  573. X * Return values: pointer to new created attribute upon success /             *
  574. X *                NULL during error handling                                  *
  575. X ******************************************************************************/
  576. XTQL_ATTR *
  577. Xgen_type_qualifier_list_attr(type_qualifier)
  578. XTQ_ATTR *type_qualifier;
  579. X{
  580. X    register TQL_ATTR *ptr;
  581. X
  582. X#ifdef STRUCTDEBUG
  583. X    fprintf(debugfile, "[type] ***** gen_type_qualifier_list_attr():\n");
  584. X#endif /* STRUCTDEBUG /**/
  585. X    ptr = (TQL_ATTR *) Malloc(sizeof(TQL_ATTR));
  586. X#ifdef STRUCTDEBUG
  587. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  588. X#endif /* STRUCTDEBUG /**/
  589. X    ptr->type_qualifier = type_qualifier;
  590. X    ptr->tq_list = NULL;
  591. X    return(ptr);
  592. X} /* gen_type_qualifier_list_attr */
  593. X
  594. X/******************************************************************************
  595. X * gen_declaration_specifiers_attr()                                          *
  596. X *                                                                            *
  597. X * Allocates memory for a declaration specifiers attribute and initializes it.*
  598. X *                                                                            *
  599. X * Return values: pointer to new created attribute upon success /             *
  600. X *                NULL during error handling                                  *
  601. X ******************************************************************************/
  602. XDS_ATTR *
  603. Xgen_declaration_specifiers_attr(scs, ts, tq, ds)
  604. XSCS_ATTR *scs;    /* storage class specifier */
  605. XTS_ATTR  *ts;    /* type specifier */
  606. XTQ_ATTR  *tq;    /* type qualifier */
  607. XDS_ATTR  *ds;    /* declaration specifiers */
  608. X{
  609. X    register DS_ATTR *ptr;
  610. X
  611. X#ifdef STRUCTDEBUG
  612. X    fprintf(debugfile, "[type] ***** gen_declaration_specifiers_attr():\n");
  613. X#endif /* STRUCTDEBUG /**/
  614. X    ptr = (DS_ATTR *) Malloc(sizeof(DS_ATTR));
  615. X#ifdef STRUCTDEBUG
  616. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  617. X#endif /* STRUCTDEBUG /**/
  618. X    ptr->scs = scs;
  619. X    ptr->ts  = ts;
  620. X    ptr->tq  = tq;
  621. X    ptr->ds  = ds;
  622. X    return(ptr);
  623. X} /* gen_declaration_specifiers_attr */
  624. X
  625. X/******************************************************************************
  626. X * gen_init_declarator_list_attr()                                            *
  627. X *                                                                            *
  628. X * Allocates memory for an init declarator list attribute and initializes it. *
  629. X *                                                                            *
  630. X * Return values: pointer to new created attribute upon success /             *
  631. X *                NULL during error handling                                  *
  632. X ******************************************************************************/
  633. XIDL_ATTR *
  634. Xgen_init_declarator_list_attr(id)
  635. XID_ATTR  *id;    /* init declarator */
  636. X{
  637. X    register IDL_ATTR *ptr;
  638. X
  639. X#ifdef STRUCTDEBUG
  640. X    fprintf(debugfile, "[type] ***** gen_init_declarator_list_attr():\n");
  641. X#endif /* STRUCTDEBUG /**/
  642. X    ptr = (IDL_ATTR *) Malloc(sizeof(IDL_ATTR));
  643. X#ifdef STRUCTDEBUG
  644. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  645. X#endif /* STRUCTDEBUG /**/
  646. X    ptr->id_list = NULL;
  647. X    ptr->id      = id;
  648. X    return(ptr);
  649. X} /* gen_init_declarator_list_attr */
  650. X
  651. X/******************************************************************************
  652. X * gen_init_declarator_attr()                                                 *
  653. X *                                                                            *
  654. X * Allocates memory for an init declarator attribute and initializes it.      *
  655. X *                                                                            *
  656. X * Return values: pointer to new created attribute upon success /             *
  657. X *                NULL during error handling                                  *
  658. X ******************************************************************************/
  659. XID_ATTR *
  660. Xgen_init_declarator_attr(declarator, initializer_str)
  661. XD_ATTR *declarator;
  662. Xchar   *initializer_str;
  663. X{
  664. X    register ID_ATTR *ptr;
  665. X
  666. X#ifdef STRUCTDEBUG
  667. X    fprintf(debugfile, "[type] ***** gen_init_declarator_attr():\n");
  668. X#endif /* STRUCTDEBUG /**/
  669. X    ptr = (ID_ATTR *) Malloc(sizeof(ID_ATTR));
  670. X#ifdef STRUCTDEBUG
  671. X    fprintf(debugfile, "[type]       address of new attr is %d\n", ptr);
  672. X#endif /* STRUCTDEBUG /**/
  673. X    ptr->d = declarator;
  674. X    ptr->inistr = initializer_str;
  675. X    return(ptr);
  676. X} /* gen_init_declarator_attr */
  677. X
  678. X/******************************************************************************
  679. X * add_type_qualifier()                                                       *
  680. X *                                                                            *
  681. X * Chains type qualifier list 'tq_list2' to the end of type qualifier list    *
  682. X * 'tq_list1'.                                                                *
  683. X *                                                                            *
  684. X * Return values: pointer to new created attribute upon success /             *
  685. X *                NULL during error handling                                  *
  686. X ******************************************************************************/
  687. XTQL_ATTR *
  688. Xadd_type_qualifier(tq_list1, tq_list2)
  689. XTQL_ATTR *tq_list1, *tq_list2;
  690. X{
  691. X    register TQL_ATTR *ptr;
  692. X
  693. X#ifdef STRUCTDEBUG
  694. X    fprintf(debugfile, "[type] ***** add_type_qualifier():\n");
  695. X    fprintf(debugfile, "[type]       params: tq_list1 = %d, tq_list2 = %d\n",
  696. X    tq_list1, tq_list2);
  697. X#endif /* STRUCTDEBUG /**/
  698. X    for(ptr = tq_list1; ptr->tq_list; ptr = ptr->tq_list)
  699. X    ;
  700. X    ptr->tq_list = tq_list2;
  701. X    return(tq_list1);
  702. X} /* add_type_qualifier */
  703. X
  704. X/******************************************************************************
  705. X * add_struct_declarator()                                                    *
  706. X *                                                                            *
  707. X * Chains struct declarator list 'sd_list2' to the end of struct declarator   *
  708. X * list 'sd_list1'.                                                           *
  709. X *                                                                            *
  710. X * Return values: pointer to new created attribute upon success /             *
  711. X *                NULL during error handling                                  *
  712. X ******************************************************************************/
  713. XSDL_ATTR *
  714. Xadd_struct_declarator(sd_list1, sd_list2)
  715. XSDL_ATTR *sd_list1, *sd_list2;
  716. X{
  717. X    register SDL_ATTR *ptr;
  718. X
  719. X#ifdef STRUCTDEBUG
  720. X    fprintf(debugfile, "[type] ***** add_struct_declarator():\n");
  721. X    fprintf(debugfile, "[type]       params: sd_list1 = %d, sd_list2 = %d\n",
  722. X        sd_list1, sd_list2);
  723. X#endif /* STRUCTDEBUG /**/
  724. X    for(ptr = sd_list1; ptr->sd_list; ptr = ptr->sd_list)
  725. X    ;
  726. X    ptr->sd_list = sd_list2;
  727. X    return(sd_list1);
  728. X} /* add_struct_declarator */
  729. X
  730. X/******************************************************************************
  731. X * add_struct_declaration()                                                   *
  732. X *                                                                            *
  733. X * Chains struct declaration list 'st_list2' to the end of struct declaration *
  734. X * list 'st_list1'.                                                           *
  735. X *                                                                            *
  736. X * Return values: pointer to new created attribute upon success /             *
  737. X *                NULL during error handling                                  *
  738. X ******************************************************************************/
  739. XSTL_ATTR *
  740. Xadd_struct_declaration(st_list1, st_list2)
  741. XSTL_ATTR *st_list1, *st_list2;
  742. X{
  743. X    register STL_ATTR *ptr;
  744. X
  745. X#ifdef STRUCTDEBUG
  746. X    fprintf(debugfile, "[type] ***** add_struct_declaration():\n");
  747. X    fprintf(debugfile, "[type]       params: st_list1 = %d, st_list2 = %d\n",
  748. X        st_list1, st_list2);
  749. X#endif /* STRUCTDEBUG /**/
  750. X    for(ptr = st_list1; ptr->st_list; ptr = ptr->st_list)
  751. X    ;
  752. X    ptr->st_list = st_list2;
  753. X    return(st_list1);
  754. X} /* add_struct_declaration */
  755. X
  756. X/******************************************************************************
  757. X * add_spec_qual_list()                                                       *
  758. X *                                                                            *
  759. X * Chains specifier qualifier list 'sq_list2' to the end of specifier         *
  760. X * qualifier list 'sq_list1'.                                                 *
  761. X *                                                                            *
  762. X * Return values: pointer to new created attribute upon success /             *
  763. X *                NULL during error handling                                  *
  764. X ******************************************************************************/
  765. XSQL_ATTR *
  766. Xadd_spec_qual_list(sq_list1, sq_list2)
  767. XSQL_ATTR *sq_list1, *sq_list2;
  768. X{
  769. X    register SQL_ATTR *ptr;
  770. X
  771. X#ifdef STRUCTDEBUG
  772. X    fprintf(debugfile, "[type] ***** add_spec_qual_list():\n");
  773. X    fprintf(debugfile, "[type]       params: sq_list1 = %d, sq_list2 = %d\n",
  774. X        sq_list1, sq_list2);
  775. X#endif /* STRUCTDEBUG /**/
  776. X    for(ptr = sq_list1; ptr->sq_list; ptr = ptr->sq_list)
  777. X    ;
  778. X    ptr->sq_list = sq_list2;
  779. X    return(sq_list1);
  780. X} /* add_spec_qual_list */
  781. X
  782. X/******************************************************************************
  783. X * add_init_declarator_list()                                                 *
  784. X *                                                                            *
  785. X * Chains init declarator list 'id_list2' to the end of init declarator list  *
  786. X * 'id_list1'.                                                                *
  787. X *                                                                            *
  788. X * Return values: pointer to new created attribute upon success /             *
  789. X *                NULL during error handling                                  *
  790. X ******************************************************************************/
  791. XIDL_ATTR *
  792. Xadd_init_declarator_list(id_list1, id_list2)
  793. XIDL_ATTR *id_list1, *id_list2;
  794. X{
  795. X    register IDL_ATTR *ptr;
  796. X
  797. X#ifdef STRUCTDEBUG
  798. X    fprintf(debugfile, "[type] ***** add_init_declarator_list():\n");
  799. X    fprintf(debugfile, "[type]       params: id_list1 = %d, id_list2 = %d\n",
  800. X        id_list1, id_list2);
  801. X#endif /* STRUCTDEBUG /**/
  802. X    for(ptr = id_list1; ptr->id_list; ptr = ptr->id_list)
  803. X    ;
  804. X    ptr->id_list = id_list2;
  805. X    return(id_list1);
  806. X} /* add_init_declarator_list */
  807. X
  808. X/******************************************************************************
  809. X * store_struct_or_type_def()                                                 *
  810. X *                                                                            *
  811. X * Stores a structure or type definition in the 'structure or type definition *
  812. X * list' by generating a new list element and appending it to the end of the  *
  813. X * list.                                                                      *
  814. X *                                                                            *
  815. X * Return values: pointer to stored symbol table entry upon success /         *
  816. X *                NULL during error handling                                  *
  817. X ******************************************************************************/
  818. XSYMBTABEL *
  819. Xstore_struct_or_type_def(symbol)
  820. XSYMBTABEL *symbol;
  821. X{
  822. X    register struct struct_type_list *ptr;
  823. X
  824. X#ifdef STRUCTDEBUG
  825. X    fprintf(debugfile, "[type] ***** store_struct_or_type_def(%s):\n",
  826. X    symbol->name);
  827. X#endif /* STRUCTDEBUG /**/
  828. X    ptr = (struct struct_type_list *) Malloc(sizeof(struct struct_type_list));
  829. X    ptr->symbol = symbol;
  830. X    ptr->next   = NULL;
  831. X    if (!first_structtype)
  832. X    first_structtype = last_structtype = ptr;
  833. X    else {
  834. X    last_structtype->next = ptr;
  835. X    last_structtype = ptr;
  836. X    }
  837. X    return(symbol);
  838. X} /* store_struct_or_type_def */
  839. END_OF_FILE
  840. if test 35350 -ne `wc -c <'dcc/attr_decl.c'`; then
  841.     echo shar: \"'dcc/attr_decl.c'\" unpacked with wrong size!
  842. fi
  843. # end of 'dcc/attr_decl.c'
  844. fi
  845. if test -f 'lib/creation.c' -a "${1}" != "-c" ; then 
  846.   echo shar: Will not clobber existing file \"'lib/creation.c'\"
  847. else
  848. echo shar: Extracting \"'lib/creation.c'\" \(35757 characters\)
  849. sed "s/^X//" >'lib/creation.c' <<'END_OF_FILE'
  850. X/***************************************************************************
  851. X *                                                                         *
  852. X * @@@@  @@@ @@@@@ @@@@@ @@@@@ @@@ @@@@  @   @ @@@@@ @@@@@ @@@@       @@@  *
  853. X * @   @  @  @       @   @   @  @  @   @ @   @   @   @     @   @     @   @ *
  854. X * @   @  @  @@@@@   @   @@@@@  @  @@@@@ @   @   @   @@@@@ @   @     @     *
  855. X * @   @  @      @   @   @ @    @  @   @ @   @   @   @     @   @     @   @ *
  856. X * @@@@  @@@ @@@@@   @   @  @  @@@ @@@@  @@@@@   @   @@@@@ @@@@       @@@  *
  857. X *                                                                         *
  858. X *              A compiler for distributed programming with C              *
  859. X *                                                                         *
  860. X *                          c r e a t i o n . c                            *
  861. X *                                                                         *
  862. X *                            Package : Runtime Library                    *
  863. X *                            Version : 1.0                                *
  864. X *                       CreationDate : 26.07.90                           *
  865. X *                         LastUpDate : 06.12.93                           *
  866. X *                                                                         *
  867. X *          All library routines needed during process creation.           *
  868. X *                                                                         *
  869. X *                  Portions Copyright 1990 Markus Pleier                  *
  870. X *               Copyright (C) 1990-1994 by Christoph Pleier               *
  871. X *                          All rights reserved!                           *
  872. X ***************************************************************************/
  873. X
  874. X/*
  875. X * This file is part of the Distributed C Development Environment (DCDE).
  876. X * DCDE is free software; you can redistribute it and/or modify
  877. X * it under the terms written in the README-file. 
  878. X * DCDE is distributed in the hope that it will be useful,
  879. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  880. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  881. X * See the file README for more details.
  882. X */
  883. X
  884. X#include <stdio.h>
  885. X#include <stdlib.h>
  886. X#include <sys/types.h>
  887. X#ifdef HETEROGENEOUS
  888. X# include <rpc/rpc.h>
  889. X#endif
  890. X#include "ipc.h"
  891. X#include "dcc.h"
  892. X#include "run_Errno.h"
  893. X#include "timeout.h"
  894. X#include "config.h"
  895. X
  896. X#define DEBUG_CREATION /**/
  897. X
  898. X#ifdef DEBUG_CREATION
  899. X/* the flag to control the debug messages output */
  900. Xint _debug_creation = 0;
  901. X#endif /* DEBUG_CREATION /**/
  902. X
  903. X#ifdef DEBUG_CREATION
  904. X# define DEBUGPUTS(msg)        if (_debug_creation) { \
  905. X                    fprintf(_debugout, "[cre] %s %s\n", \
  906. X                        _processprefix, msg); \
  907. X                    if (_debugflush) \
  908. X                        fflush(_debugout); \
  909. X                }
  910. X# define DEBUGDISPERR(msg)    if (_debug_creation) { \
  911. X                    fprintf(_debugout, "[cre] %s error: %s\n", \
  912. X                        _processprefix, msg); \
  913. X                    fprintf(_debugout, "[cre] %s reason: %s\n",\
  914. X                        _processprefix, sys_errlist[errno]); \
  915. X                    if (_debugflush) \
  916. X                        fflush(_debugout); \
  917. X                }
  918. X#else
  919. X# define DEBUGPUTS(msg)        { /* nothing */ }
  920. X# define DEBUGDISPERR(msg)    { /* nothing */ }
  921. X#endif
  922. X
  923. X/*
  924. X * The process creation is divided in the following steps:
  925. X *
  926. X * (CP = Creator Process, NP = New Process, AP = Administration Process)
  927. X *
  928. X * I. iPSC (Intel Hypercube):
  929. X * --------------------------
  930. X *    1)  CP creates NP (load(..))
  931. X *    2a) CP establishes connection to NP (_make_connection(...))
  932. X *    2b) NP accepts connection from CP (_accept_connection(...))
  933. X *    3)  CP sends creator and admin port info to NP (_send_data(...))
  934. X *    4)  NP receives the port info (_recv_data(...))
  935. X *    5)  CP sends process parameters (if any) (_send_data(...))
  936. X *    6)  NP receives process parameters (if any) (_recv_data(...))
  937. X *    7)  NP sends its process data to AP
  938. X *
  939. X * II. Unix Systems (SunOs, ConvexOs, SCO Xenix/Unix, ...):
  940. X * --------------------------------------------------------
  941. X *    1)  CP creates NP (fork() and exec(NP) or exec("rsh", NP,...))
  942. X *    2a) CP accepts connection from NP (_accept_connection(...))
  943. X *    2b) NP establishes connection to CP (_make_connection(...))
  944. X *    3)  NP sends its process data to CP (_send_data(...))
  945. X *    4)  CP receives process data from NP (_recv_data(...))
  946. X *    5)  CP sends process parameters (if any) (_send_data(...))
  947. X *    6)  NP receives process parameters (if any) (_recv_data(...))
  948. X *    7)  NP sends its process data to AP
  949. X *
  950. X * The various steps are performed by the following functions:
  951. X *
  952. X * a) creator process
  953. X *
  954. X * |            iPSC                    |            Unix Systems             |
  955. X * ----------------------------------------------------------------------------
  956. X * | 1)  _generate_process(...)         | 1)  _generate_process(...)          |
  957. X * | 2a) _make_connection(...)          | 2a) _accept_connection(...)         |
  958. X * | 3)  _send_ports_data(...)          | 4)  _receive_process_data(...)      |
  959. X * | 5)  { send parameters }            | 5)  { send parameters }             |
  960. X * ----------------------------------------------------------------------------
  961. X *
  962. X * a) new process
  963. X *
  964. X * |            iPSC                    |            Unix Systems             |
  965. X * ----------------------------------------------------------------------------
  966. X * | 2b) _accept_connection(...)        | 2b) _make_connection(...)           |
  967. X * | 4)  _receive_ports_data(...)       | 3)  _send_process_data(...)         |
  968. X * | 6)  { receive parameters }         | 6)  { receive parameters }          |
  969. X * | 7)  _notify_admin_process(...)     | 7)  _notify_admin_process(...)      |
  970. X * ----------------------------------------------------------------------------
  971. X *
  972. X * Note: The actions in braces are generated at compile time!
  973. X */
  974. X
  975. X/*
  976. X * The following global variables are used to pass data between functions
  977. X */
  978. X
  979. Xextern int              Errno;         /* to pass error code */
  980. Xextern char            *_programname,  /* programname of actual process */
  981. X                       *_processname;  /* processname of actual process */
  982. Xextern PORTDESCR        _own_port,     /* own port */
  983. X                        _creator_port, /* port of creator process */
  984. X                        _admin_port;   /* port of administration process */
  985. Xextern CONNECTIONDESCR  _con_port;     /* port specifying connections */
  986. X
  987. X#ifdef iPSC
  988. X
  989. X/******************************************************************************
  990. X * _generate_process()                                           iPSC Version *
  991. X *                                                                            *
  992. X * Generates the process 'process' at the node 'node' with the process id     *
  993. X * 'pid' using the load-command.                                              *
  994. X *                                                                            *
  995. X * Return values: always OK for success                                       *
  996. X ******************************************************************************/
  997. Xstatic int
  998. X_generate_process(process, node, pid)
  999. Xchar *process;    /* which process to generate */
  1000. Xlong  node;    /* where to generate new process */
  1001. Xlong  pid;    /* process id of new process */
  1002. X{
  1003. X#ifdef DEBUG_CREATION
  1004. X    if (_debug_creation) {
  1005. X        fprintf(_debugout, "[cre] %s ***** _generate_process():\n", _processprefix);
  1006. X        fprintf(_debugout, "[cre] %s generating \"%s\" at node %ld with pid %ld\n",
  1007. X        _processprefix, process, node, pid);
  1008. X        if (_debugflush)
  1009. X        fflush(_debugout);
  1010. X    }
  1011. X#endif /* DEBUG_CREATION /**/
  1012. X    load(process, node, pid);
  1013. X    Errno = -1;
  1014. X    return(OK);
  1015. X} /* _generate_process */
  1016. X
  1017. X/******************************************************************************
  1018. X * _send_ports_data()                                            iPSC Version *
  1019. X *                                                                            *
  1020. X * Sends the port information of the creator and administration process to    *
  1021. X * the process connected to by '_con_port'.                                   *
  1022. X *                                                                            *
  1023. X * Return values: OK upon success / ERROR upon error                          *
  1024. X ******************************************************************************/
  1025. Xstatic int
  1026. X_send_ports_data()
  1027. X{
  1028. X    PORTSDATA portsinfo;
  1029. X
  1030. X#ifdef DEBUG_CREATION
  1031. X    if (_debug_creation) {
  1032. X        fprintf(_debugout, "[cre] %s ***** _send_ports_data():\n",
  1033. X        _processprefix);
  1034. X        fprintf(_debugout, "[cre] %s sending creator and admin port data\n", 
  1035. X        _processprefix);
  1036. X        if (_debugflush)
  1037. X        fflush(_debugout);
  1038. X    }
  1039. X#endif /* DEBUG_CREATION /**/
  1040. X    portsinfo.creator_port = _own_port;
  1041. X    portsinfo.admin_port   = _admin_port;
  1042. X    if (_send_data(&_con_port, (char *) &portsinfo, sizeof(PORTSDATA), CPTONPPDATTIME) < 0) {
  1043. X    if (Errno == ETIMEOUT)
  1044. X        Errno = ETCCPTONPPDAT;
  1045. X    return(ERROR);
  1046. X    }
  1047. X    Errno = -1;
  1048. X    return(OK);
  1049. X} /* _send_ports_data */
  1050. X
  1051. X/******************************************************************************
  1052. X * _receive_ports_data()                                         iPSC Version *
  1053. X *                                                                            *
  1054. X * Receives the port information of the creator and administration process    *
  1055. X * from the process connected to by '_con_port' and initializes the global    *
  1056. X * variables '_creator_port' and '_admin_port'.                               *
  1057. X *                                                                            *
  1058. X * Return values: OK upon success / ERROR upon error                          *
  1059. X ******************************************************************************/
  1060. Xint
  1061. X_receive_ports_data()
  1062. X{
  1063. X    PORTSDATA portsinfo;
  1064. X
  1065. X    DEBUGPUTS("receiving creator and admin port data");
  1066. X    if (_recv_data(&_con_port, (char *) &portsinfo, sizeof(PORTSDATA), NPTOCPPDATTIME) < 0) {
  1067. X    if (Errno == ETIMEOUT)
  1068. X        Errno = ETCNPGETPDAT;
  1069. X    return(ERROR);
  1070. X    }
  1071. X    _creator_port = portsinfo.creator_port;
  1072. X    _admin_port   = portsinfo.admin_port;
  1073. X#ifdef DEBUG_CREATION
  1074. X    if (_debug_creation) {
  1075. X        _display_port_info("[cre]", "_creator_port", _creator_port);
  1076. X        _display_port_info("[cre]", "_admin_port  ", _admin_port);
  1077. X        if (_debugflush)
  1078. X        fflush(_debugout);
  1079. X    }
  1080. X#endif /* DEBUG_CREATION /**/
  1081. X    Errno = -1;
  1082. X    return(OK);
  1083. X} /* _receive_ports_data */
  1084. X
  1085. X/******************************************************************************
  1086. X * _create_process()                                             iPSC Version *
  1087. X *                                                                            *
  1088. X * Creates the process 'process' at the node specified by 'location'. If      *
  1089. X * location equals NULL, the target node is choosen according to the entries  *
  1090. X * in the configuration file by consulting the administration process.        *
  1091. X * The result parameter 'p_descr' is initialized with the process descriptor  *
  1092. X * of the new generated process.                                              *
  1093. X *                                                                            *
  1094. X * Return values: OK upon success / ERROR upon error                          *
  1095. X ******************************************************************************/
  1096. Xint
  1097. X_create_process(process, location, p_descr)
  1098. Xchar         *process,   /* which process to start */
  1099. X             *location;  /* where to start process */
  1100. XPROCESSDESCR *p_descr;   /* process descriptor (result parameter) */
  1101. X{
  1102. X    char        tmpstr[20];
  1103. X    PORTDESCR   other_port;
  1104. X    extern long _pidcount;
  1105. X
  1106. X    if (location == NULL) {
  1107. X        /* Choose target node by hostfile and continue */
  1108. X        DEBUGPUTS("choosing target node by nodefile!");
  1109. X    if (_get_location_from_admin(process, &location))
  1110. X        return(ERROR);
  1111. X    /* Note: In the configuration files nodes must be specified in the
  1112. X     *       form: "node-x" where x is the node number. Therefore we 
  1113. X     *       must remove the prefix "node-"!
  1114. X     */
  1115. X    location += 5;
  1116. X    } 
  1117. X#ifdef DEBUG_CREATION
  1118. X    if (_debug_creation) {
  1119. X        fprintf(_debugout, "[cre] %s creating process \"%s\"\n",
  1120. X        _processprefix, process);
  1121. X    }
  1122. X#endif /* DEBUG_CREATION /**/
  1123. X    if (!strcmp(location, "local")) {
  1124. X    /* CASE 1: Target node is own node */
  1125. X    if (_generate_process(process, mynode(), _pidcount))
  1126. X        return(ERROR);
  1127. X    init_port(&other_port, mynode(), _pidcount++);
  1128. X    } else {
  1129. X        /* CASE 2: Target node is an other node */
  1130. X    if (_generate_process(process, atol(location), _pidcount))
  1131. X        return(ERROR);
  1132. X    init_port(&other_port, atol(location), _pidcount++);
  1133. X    }
  1134. X    DEBUGPUTS("connecting to NP");
  1135. X    /* make connection to new process to send parameters */
  1136. X    if (_make_connection(&_con_port, &_own_port, &other_port, CPTONPCONTIME)) {
  1137. X        if (Errno == ETIMEOUT)
  1138. X            Errno = ETCCPTONPCON;
  1139. X        return(ERROR);
  1140. X    }
  1141. X    DEBUGPUTS("sending ports data to NP");
  1142. X    if (_send_ports_data())
  1143. X    return(ERROR);
  1144. X    /* set result parameter */
  1145. X    strcpy(p_descr->processname, process);
  1146. X    p_descr->pid  = _pidcount - 1;
  1147. X    p_descr->port = other_port;
  1148. X    Errno = -1;
  1149. X    return(OK);
  1150. X} /* _create_process */
  1151. X
  1152. X#else /* AIX || CONVEX || HPUX || LINUX || SPARC || UNICOS || ... /**/  
  1153. X
  1154. X/******************************************************************************
  1155. X * _generate_process()                                   Unix Systems Version *
  1156. X *                                                                            *
  1157. X * Generates the process 'process' at the host 'host' using the system calls  *
  1158. X * fork and exec. Processes at foreign hosts are created by a combination of  *
  1159. X * exec with the remote shell (rsh).                                          *
  1160. X * Remark: The Xenix Version creates processes always at the local machine.   *
  1161. X *                                                                            *
  1162. X * Return values: OK upon success / ERROR upon error                          *
  1163. X ******************************************************************************/
  1164. Xstatic int
  1165. X_generate_process(process, host)
  1166. Xchar *process;    /* which process to generate */ 
  1167. Xchar *host;    /* where to generate new process */
  1168. X{
  1169. X    static char *parv[10];     /* to store arguments for exec */
  1170. X#ifndef SINGLE
  1171. X    static char *tmpstr1[10];
  1172. X    static char *tmpstr2[10];
  1173. X#endif /* SINGLE /**/
  1174. X
  1175. X#ifdef DEBUG_CREATION
  1176. X    if (_debug_creation) {
  1177. X        fprintf(_debugout, "[cre] %s generating \"%s\" at host \"%s\"\n", 
  1178. X        _processprefix, process, host);
  1179. X        fprintf(_debugout, "[cre] %s generating child process using fork()\n",
  1180. X        _processprefix);
  1181. X        if (_debugflush)
  1182. X        fflush(_debugout);
  1183. X    }
  1184. X#endif /* DEBUG_CREATION /**/
  1185. X    switch(fork()) {
  1186. X    case -1: /* error! */
  1187. X    Errno = EPROCESSCREAT;
  1188. X        return(ERROR);
  1189. X        /* break */
  1190. X    case 0: /* child! */
  1191. X#ifndef SINGLE
  1192. X    if (!strcmp(host, _own_port.hostname)) {
  1193. X#endif /* !SINGLE /**/
  1194. X        /* CASE 1: Target host is local host */
  1195. X            DEBUGPUTS("target host is own host!");
  1196. X            parv[0] = process;
  1197. X            _convert_port_to_argv(parv, _own_port, _admin_port);
  1198. X            DEBUGPUTS("transforming to new process using execvp()");
  1199. X        execvp(process, parv);
  1200. X        /* Note: execv returns only upon error */
  1201. X#ifndef SINGLE
  1202. X        } else {
  1203. X        /* CASE 2: Target host is a remote host */
  1204. X            DEBUGPUTS("target host is a remote host");
  1205. X        sprintf((char *) tmpstr1, "%d", _own_port.portnum);
  1206. X        sprintf((char *) tmpstr2, "%d", _admin_port.portnum);
  1207. X            DEBUGPUTS("transforming to new process using execlp(\"rsh\", ...)");
  1208. X#ifdef UNICOS
  1209. X        execlp("remsh", "remsh", host, "-n", "exec", process,
  1210. X#else
  1211. X        execlp("rsh", "rsh", host, "-n", "exec", process,
  1212. X#endif /* UNICOS /**/
  1213. X        tmpstr1, _own_port.hostname,
  1214. X        tmpstr2, _admin_port.hostname,
  1215. X        (char *) NULL);
  1216. X        /* Note: execlp returns only upon error */
  1217. X    }
  1218. X#endif /* Not SINGLE /**/
  1219. X    /* The following code is only executed upon error, because exec
  1220. X     * returns only when an error has occured! Therefore we send an
  1221. X     * error message to the creator process.
  1222. X     */
  1223. X    if (!strcmp(process, "dcadmin"))
  1224. X        perror("Fatal error in execvp()");
  1225. X    else {
  1226. X        DEBUGDISPERR("Error in exec()");
  1227. X        _notify_admin_process(NOTIFY_ERROR);
  1228. X    }
  1229. X    exit(ERROR);
  1230. X    /* break; */
  1231. X    default: /* parent! */
  1232. X        Errno = -1;
  1233. X    return(OK);
  1234. X    } /* switch */
  1235. X} /* _generate_process */
  1236. X
  1237. X/******************************************************************************
  1238. X * _create_dcadmin()                                     Unix Systems Version *
  1239. X *                                                                            *
  1240. X * Creates the administration process at the local machine and sends the name *
  1241. X * of the configuration file 'filename' to it.                                *
  1242. X * The global variable '_admin_port' is initialized to specify the created    *
  1243. X * process.                                                                   *
  1244. X *                                                                            *
  1245. X * Return values: OK upon success / ERROR upon error                          *
  1246. X ******************************************************************************/
  1247. Xint
  1248. X_create_dcadmin(adminpath, filename)
  1249. Xchar *adminpath, /* name of the administration process (complete path) */
  1250. X     *filename;     /* name of the configuration file */
  1251. X{
  1252. X    PROCESSDATA pdata;    /* process data variable */
  1253. X
  1254. X    DEBUGPUTS("creating admin process"); 
  1255. X#ifdef MSGSEM
  1256. X    init_port(&_admin_port, 0, 0);
  1257. X#else /* SOCKET /**/
  1258. X    init_port(&_admin_port, 0, 0, "");
  1259. X#endif /* MSGSEM /**/
  1260. X#ifdef SINGLE
  1261. X    if (_generate_process(adminpath, "local"))
  1262. X    return(ERROR);
  1263. X#else
  1264. X    if (_generate_process(adminpath, _own_port.hostname))
  1265. X    return(ERROR);
  1266. X#endif /* SINGLE /**/
  1267. X    DEBUGPUTS("accepting connection from admin process"); 
  1268. X    if (_accept_connection(&_con_port, &_own_port, CPTONPACCTIME)) {
  1269. X    if (Errno == ETIMEOUT)
  1270. X        Errno = ETCCPTONPACC;
  1271. X    return(ERROR);
  1272. X    }
  1273. X    DEBUGPUTS("receiving process data from admin process"); 
  1274. X    if (_receive_process_data(&pdata))
  1275. X        return(ERROR);
  1276. X    if (_close_connection(&_con_port))
  1277. X    return(ERROR);
  1278. X    /* initialize admin port variable */
  1279. X    _admin_port = pdata.port;
  1280. X#ifdef DEBUG_CREATION
  1281. X    if (_debug_creation) 
  1282. X        _display_port_info("[cre]", "setting _admin_port to", _admin_port); 
  1283. X#endif /* DEBUG_CREATION /**/
  1284. X    /* send filename of configuration file to administration process */
  1285. X    if (_send_filename_to_admin(filename))
  1286. X    return(ERROR);
  1287. X    /* send own process data to administration process */
  1288. X    if (_notify_admin_process(NOTIFY_START))
  1289. X    return(ERROR);
  1290. X    Errno = -1;
  1291. X    return(OK);
  1292. X} /* _create_dcadmin */
  1293. X
  1294. X/******************************************************************************
  1295. X * _create_process()                                     Unix Systems Version *
  1296. X *                                                                            *
  1297. X * Creates the process 'process' at the host specified by 'location'. If      *
  1298. X * location equals NULL, the target host is choosen according to the entries  *
  1299. X * in the configuration file by consulting the administration process.        *
  1300. X * The result parameter 'p_descr' is initialized with the process descriptor  *
  1301. X * of the new generated process.                                              *
  1302. X *                                                                            *
  1303. X * Return values: OK upon success / ERROR upon error                          *
  1304. X ******************************************************************************/
  1305. Xint
  1306. X_create_process(processname, process, location, p_descr)
  1307. Xchar         *processname,     /* name of process to start */
  1308. X             *process,         /* corresponding file name */
  1309. X             *location;        /* where to start process */
  1310. XPROCESSDESCR *p_descr;         /* process descriptor (result parameter) */
  1311. X{
  1312. X    PROCESSDATA pdata;
  1313. X
  1314. X    if (location == NULL) {
  1315. X    /* Choose target host by hostfile and continue */
  1316. X    DEBUGPUTS("choosing target host by hostfile!");
  1317. X    if (_get_location_from_admin(processname, process, &location))
  1318. X        return(ERROR);
  1319. X    } 
  1320. X#ifdef DEBUG_CREATION
  1321. X    if (_debug_creation) {
  1322. X        fprintf(_debugout, "[cre] %s creating process \"%s\" (\"%s\") at \"%s\"\n", 
  1323. X        _processprefix, processname, process, location);
  1324. X    }
  1325. X#endif /* DEBUG_CREATION /**/
  1326. X#ifdef SINGLE
  1327. X    if (_generate_process(process, "local"))
  1328. X    return(ERROR);
  1329. X#else
  1330. X    if (!strcmp(location, "local"))
  1331. X    location = _own_port.hostname;
  1332. X    if (_generate_process(process, location))
  1333. X    return(ERROR);
  1334. X#endif /* SINGLE /**/
  1335. X    while(1) {
  1336. X        DEBUGPUTS("accepting connection from NP");
  1337. X        /* accept connections to receive reply message */
  1338. X        if (_accept_connection(&_con_port, &_own_port, CPTONPACCTIME)) {
  1339. X        if (Errno == ETIMEOUT)
  1340. X            Errno = ETCCPTONPACC;
  1341. X        return(ERROR);
  1342. X        }
  1343. X        DEBUGPUTS("receiving connection type");
  1344. X    if (_receive_connection_type_or_answer() == CREATION_CONNECTION)
  1345. X        break;
  1346. X        DEBUGPUTS("wrong connection accepted");
  1347. X        DEBUGPUTS("sending connection aborted (ABORT...)");
  1348. X    if (_send_connection_type_or_answer(ABORT_CONNECTION))
  1349. X        return(ERROR);
  1350. X        DEBUGPUTS("closing connection and trying again");
  1351. X        if (_close_connection(&_con_port))
  1352. X        return(ERROR);
  1353. X    }
  1354. X    DEBUGPUTS("sending connection accepted (ACCEPT...)");
  1355. X    if (_send_connection_type_or_answer(ACCEPT_CONNECTION))
  1356. X        return(ERROR);
  1357. X    DEBUGPUTS("receiving process data from NP");
  1358. X    if (_receive_process_data(&pdata))
  1359. X    return(ERROR);
  1360. X    /* return result using the reference parameter */
  1361. X    strcpy(p_descr->processname, pdata.processname);
  1362. X    p_descr->pid  = pdata.pid;
  1363. X    p_descr->port = pdata.port;
  1364. X    Errno = -1;
  1365. X    return(OK);
  1366. X} /* _create_process */
  1367. X
  1368. X/******************************************************************************
  1369. X * _report_back()                                        Unix Systems Version *
  1370. X *                                                                            *
  1371. X * Makes a connection to the creator process and sends the own process info   *
  1372. X * to it. This function is called by every new created process to report back *
  1373. X * to the creator process.                                                    *
  1374. X *                                                                            *
  1375. X * Return values: OK upon success / ERROR upon error                          *
  1376. X ******************************************************************************/
  1377. Xint
  1378. X_report_back()
  1379. X{
  1380. X    DEBUGPUTS("reporting back to creator process");
  1381. X    /* connect to creator process */
  1382. X    while(1) {
  1383. X        DEBUGPUTS("connecting");
  1384. X        if (_make_connection(&_con_port, &_own_port, &_creator_port, NPTOCPCONTIME)) {
  1385. X        if (Errno == ETIMEOUT)
  1386. X            Errno = ETCNPTOCPCON;
  1387. X        return(ERROR);
  1388. X        }
  1389. X        DEBUGPUTS("sending connection type (CREAT...)");
  1390. X        if (_send_connection_type_or_answer(CREATION_CONNECTION))
  1391. X        return(ERROR);
  1392. X        DEBUGPUTS("receiving connection answer");
  1393. X    if (_receive_connection_type_or_answer() == ACCEPT_CONNECTION)
  1394. X        break;
  1395. X        DEBUGPUTS("connection not accepted");
  1396. X        DEBUGPUTS("closing connection and trying again");
  1397. X        if (_close_connection(&_con_port))
  1398. X        return(ERROR);
  1399. X    }
  1400. X    if (_send_process_data(OK))
  1401. X    return(ERROR);
  1402. X    Errno = -1;
  1403. X    return(OK);
  1404. X} /* _report_back */
  1405. X
  1406. X#endif /* iPSC /**/
  1407. X
  1408. X/******************************************************************************
  1409. X * _send_connection_type_or_answer()                                          *
  1410. X *                                                                            *
  1411. X * Sends the connection type info 'type' to the process connected to by the   *
  1412. X * connection descriptor '_con_port'.                                         *
  1413. X *                                                                            *
  1414. X * Return values: OK upon success / ERROR upon error                          *
  1415. X ******************************************************************************/
  1416. Xint
  1417. X_send_connection_type_or_answer(type)
  1418. Xint type;
  1419. X{
  1420. X    static char sendstr[10];
  1421. X
  1422. X    sprintf(sendstr, "%d", type);
  1423. X    if (_send_data(&_con_port, sendstr, 10, CONNTYPESNDTIME) < 0){
  1424. X    if (Errno == ETIMEOUT)
  1425. X        Errno = ETCONNTYPESND;
  1426. X    return(ERROR);
  1427. X    }
  1428. X    Errno = -1;
  1429. X    return(OK);
  1430. X} /* _send_connection_type_or_answer */
  1431. X
  1432. X/******************************************************************************
  1433. X * _receive_connection_type_or_answer()                                       *
  1434. X *                                                                            *
  1435. X * Receives a connection type info from the process connected to by the       *
  1436. X * connection descriptor '_con_port'.                                         *
  1437. X *                                                                            *
  1438. X * Return values: received connection type upon success / ERROR upon error    *
  1439. X ******************************************************************************/
  1440. Xint
  1441. X_receive_connection_type_or_answer()
  1442. X{
  1443. X    int msg_type;
  1444. X    static char recvstr[10];
  1445. X
  1446. X    if (_recv_data(&_con_port, recvstr, 10, CONNTYPERCVTIME) < 0){
  1447. X    if (Errno == ETIMEOUT)
  1448. X        Errno = ETCONNTYPERCV;
  1449. X    return(ERROR);
  1450. X    }
  1451. X    msg_type = atoi(recvstr);
  1452. X    Errno = -1;
  1453. X    return(msg_type);
  1454. X} /* _receive_connection_type_or_answer */
  1455. X
  1456. X/******************************************************************************
  1457. X * _send_process_data()                                                       *
  1458. X *                                                                            *
  1459. X * Sends the own process information to the process connected to by the       *
  1460. X * connection descriptor '_con_port'.                                         *
  1461. X *                                                                            *
  1462. X * Return values: OK upon success / ERROR upon error                          *
  1463. X ******************************************************************************/
  1464. Xint
  1465. X_send_process_data(error)
  1466. Xint error;
  1467. X{
  1468. X    PROCESSDATA pdata;
  1469. X
  1470. X    DEBUGPUTS("sending process data");
  1471. X    strcpy(pdata.processname, _processname);
  1472. X#ifdef iPSC
  1473. X    pdata.pid = mypid();
  1474. X#else
  1475. X    pdata.pid = getpid();
  1476. X#endif /* iPSC /**/
  1477. X    pdata.port  = _own_port;
  1478. X    pdata.error = error;
  1479. X#ifdef DEBUG_CREATION
  1480. X    if (_debug_creation) {
  1481. X        _display_processdata_info("[cre]", "process data:", pdata);
  1482. X        if (_debugflush)
  1483. X        fflush(_debugout);
  1484. X    }
  1485. X#endif /* DEBUG_CREATION /**/
  1486. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1487. X    if (_send_data(&_con_port, (char *) &pdata, sizeof(PROCESSDATA), NPTOAPSNDTIME) < 0){
  1488. X#else /* HETEROGENEOUS */
  1489. X    if (_send_data_encoded(&_con_port, (char *) &pdata, xdr_PROCESSDATA, NPTOAPSNDTIME)){
  1490. X#endif /* SINGLE || HOMOGENEOUS /**/
  1491. X    if (Errno == ETIMEOUT)
  1492. X        Errno = ETCNPTOAPSND;
  1493. X    return(ERROR);
  1494. X    }
  1495. X    Errno = -1;
  1496. X    return(OK);
  1497. X} /* _send_process_data */
  1498. X
  1499. X/******************************************************************************
  1500. X * _receive_process_data()                                                    *
  1501. X *                                                                            *
  1502. X * Receives the process information from the process connected to by the      *
  1503. X * connection descriptor '_con_port' and stores it in the result parameter    *
  1504. X * 'processdata' to pass it to the caller.                                    *
  1505. X *                                                                            *
  1506. X * Return values: OK upon success / ERROR upon error                          *
  1507. X ******************************************************************************/
  1508. Xint
  1509. X_receive_process_data(processdata)
  1510. XPROCESSDATA *processdata;
  1511. X{
  1512. X    unsigned long size;
  1513. X
  1514. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1515. X    if (_recv_data(&_con_port, (char *) processdata, sizeof(PROCESSDATA), CPTONPREPTIME) < 0) {
  1516. X#else /* HETEROGENEOUS */
  1517. X    if (_recv_data_encoded(&_con_port, (char *) processdata, xdr_PROCESSDATA, CPTONPREPTIME)) {
  1518. X#endif /* SINGLE || HOMOGENEOUS /**/
  1519. X        if (Errno == ETIMEOUT)
  1520. X            Errno = ETCCPTONPRCV;
  1521. X        return(ERROR);
  1522. X    }
  1523. X#ifdef DEBUG_CREATION
  1524. X    if (_debug_creation) {
  1525. X        _display_processdata_info("[cre]", "received process data:", *processdata);
  1526. X        if (_debugflush)
  1527. X        fflush(_debugout);
  1528. X    }
  1529. X#endif /* DEBUG_CREATION /**/
  1530. X    Errno = -1;
  1531. X    return(OK);
  1532. X} /* _receive_process_data */
  1533. X
  1534. X/******************************************************************************
  1535. X * _send_filename_to_admin()                                                  *
  1536. X *                                                                            *
  1537. X * Connects to the administration process and sends the name of the configu-  *
  1538. X * ration file to it.                                                         *
  1539. X *                                                                            *
  1540. X * Return values: OK upon success / ERROR upon error                          *
  1541. X ******************************************************************************/
  1542. Xint
  1543. X_send_filename_to_admin(filename)
  1544. Xchar *filename;
  1545. X{
  1546. X    ADMINCFGINFO    cfgfile;
  1547. X    CONNECTIONDESCR con_port;
  1548. X    unsigned long size;
  1549. X
  1550. X    if (_make_connection(&con_port, &_own_port, &_admin_port, CPTOAPCONTIME)) {
  1551. X    if (Errno == ETIMEOUT)
  1552. X        Errno = ETCCPTOAPCON;
  1553. X    return(ERROR);
  1554. X    }
  1555. X    (void) strcpy(cfgfile.filename, filename);
  1556. X    DEBUGPUTS("sending name of configuration file");
  1557. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1558. X    if (_send_data(&con_port, (char *) &cfgfile, sizeof(ADMINCFGINFO), CPTOAPSNDTIME) < 0) {
  1559. X#else /* HETEROGENEOUS */
  1560. X    if (_send_data_encoded(&con_port, (char *) &cfgfile, xdr_ADMINCFGINFO, CPTOAPSNDTIME)) {
  1561. X#endif /* SINGLE || HOMOGENEOUS /**/
  1562. X        if (Errno == ETIMEOUT)
  1563. X            Errno = ETCNPTOAPSND;
  1564. X        return(ERROR);
  1565. X    }
  1566. X    if (_close_connection(&con_port))
  1567. X    return(ERROR);
  1568. X    Errno = -1;
  1569. X    return(OK);
  1570. X} /* _send_filename_to_admin */
  1571. X
  1572. X/******************************************************************************
  1573. X * _notify_admin_process()                                                    *
  1574. X *                                                                            *
  1575. X * Connects to the administration process to report the event 'what'.         *
  1576. X * Valid events are:                                                          *
  1577. X *   - creation of a process (NOTIFY_START)                                   *
  1578. X *   - termination of a process (NOTIFY_END)                                  *
  1579. X *   - start of execution of a select statement with terminate alternative    *
  1580. X *     (NOTIFY_ACCORTER_ON)                                                   *
  1581. X *   - completion of a select statement with terminate alternative            *
  1582. X *     (NOTIFY_ACCORTER_OFF)                                                  *
  1583. X *   - Occurance of a runtime error (NOTIFY_ERROR)                            *
  1584. X *                                                                            *
  1585. X * Return values: OK upon success / ERROR upon error                          *
  1586. X ******************************************************************************/
  1587. Xint
  1588. X_notify_admin_process(what)
  1589. Xint what;
  1590. X{
  1591. X    char             *tmpptr;
  1592. X    ADMINREQUEST     adminrequest;
  1593. X    CONNECTIONDESCR  con_port;
  1594. X    unsigned long size;
  1595. X
  1596. X#ifdef DEBUG_CREATION
  1597. X    switch(what) {
  1598. X    case NOTIFY_START:
  1599. X    tmpptr = "NOTIFY_START";
  1600. X    break;
  1601. X    case NOTIFY_END:
  1602. X    tmpptr = "NOTIFY_END";
  1603. X    break;
  1604. X    case NOTIFY_ACCORTER_ON:
  1605. X    tmpptr = "NOTIFY_ACCORTER_ON";
  1606. X    break;
  1607. X    case NOTIFY_ACCORTER_OFF:
  1608. X    tmpptr = "NOTIFY_ACCORTER_OFF";
  1609. X    break;
  1610. X    case NOTIFY_ERROR:
  1611. X    tmpptr = "NOTIFY_ERROR";
  1612. X    break;
  1613. X    default:
  1614. X    tmpptr = "UNKNOWN!";
  1615. X    } /* switch */
  1616. X    if (_debug_creation) {
  1617. X        fprintf(_debugout, "[cre] %s notifying admin process:\n", 
  1618. X        _processprefix);
  1619. X        fprintf(_debugout, "[cre] %s    what = %s\n", _processprefix, tmpptr);
  1620. X        fprintf(_debugout, "[cre] %s connecting to admin process\n", 
  1621. X        _processprefix);
  1622. X    }
  1623. X#endif /* DEBUG_CREATION /**/ 
  1624. X    if (_make_connection(&con_port, &_own_port, &_admin_port, NPTOAPCONTIME)) {
  1625. X    if (Errno == ETIMEOUT)
  1626. X        Errno = ETCNPTOAPCON;
  1627. X    return(ERROR);
  1628. X    }
  1629. X    adminrequest.request_type = what;
  1630. X    DEBUGPUTS("sending request type");
  1631. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1632. X    if (_send_data(&con_port, (char *) &adminrequest, sizeof(ADMINREQUEST), NPTOAPREQTIME)<0) {
  1633. X#else /* HETEROGENEOUS */
  1634. X    if (_send_data_encoded(&con_port, (char *) &adminrequest, xdr_ADMINREQUEST, NPTOAPREQTIME)) {
  1635. X#endif /* SINGLE || HOMOGENEOUS /**/
  1636. X        if (Errno == ETIMEOUT)
  1637. X            Errno = ETCNPTOAPREQ;
  1638. X    _close_connection(&con_port);
  1639. X        return(ERROR);
  1640. X    }
  1641. X    _con_port = con_port;
  1642. X    if (_send_process_data(OK)) {
  1643. X    _close_connection(&con_port);
  1644. X        return(ERROR);
  1645. X    }
  1646. X    _close_connection(&_con_port);
  1647. X    Errno = -1;
  1648. X    return(OK);
  1649. X} /* _notify_admin_process */
  1650. X
  1651. X/******************************************************************************
  1652. X * _get_location_from_admin()                                                 *
  1653. X *                                                                            *
  1654. X * Consults the administration process where to create the process with name  *
  1655. X * 'processname'. The reference parameter 'location' is initialized with the  *
  1656. X * received result to pass it to the caller.                                  *
  1657. X *                                                                            *
  1658. X * Return values: OK upon success / ERROR upon error                          *
  1659. X ******************************************************************************/
  1660. Xint
  1661. X_get_location_from_admin(processname, processfilename, location)
  1662. Xchar  *processname,
  1663. X      *processfilename,
  1664. X     **location;
  1665. X{
  1666. X    static ADMINLOCINFO locinfo;
  1667. X    ADMINREQUEST adminrequest;
  1668. X    CONNECTIONDESCR con_port;
  1669. X    unsigned long size;
  1670. X
  1671. X    if (_make_connection(&con_port, &_own_port, &_admin_port, CPTOAPCONTIME)) {
  1672. X    if (Errno == ETIMEOUT)
  1673. X        Errno = ETCCPTOAPCON;
  1674. X    return(ERROR);
  1675. X    }
  1676. X    adminrequest.request_type = NOTIFY_GETLOCATION;
  1677. X    DEBUGPUTS("sending request type");
  1678. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1679. X    if (_send_data(&con_port, (char *) &adminrequest, sizeof(ADMINREQUEST), CPTOAPREQTIME)<0) {
  1680. X#else /* HETEROGENEOUS */
  1681. X    if (_send_data_encoded(&con_port, (char *) &adminrequest, xdr_ADMINREQUEST, CPTOAPREQTIME)) {
  1682. X#endif /* SINGLE || HOMOGENEOUS /**/
  1683. X        if (Errno == ETIMEOUT)
  1684. X            Errno = ETCCPTOAPREQ;
  1685. X        return(ERROR);
  1686. X    }
  1687. X    (void) strcpy(locinfo.processname,      processname);
  1688. X    (void) strcpy(locinfo.processfilename,  processfilename);
  1689. X#ifdef SOCKET
  1690. X    (void) strcpy(locinfo.creator_location, _own_port.hostname);
  1691. X#endif
  1692. X#ifdef SCO_UNIX
  1693. X    /* simulation mode */
  1694. X    (void) strcpy(locinfo.creator_location, "simulate");
  1695. X#endif
  1696. X    DEBUGPUTS("sending process name");
  1697. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1698. X    if (_send_data(&con_port, (char *) &locinfo, sizeof(ADMINLOCINFO), CPTOAPSNDTIME) < 0) {
  1699. X#else /* HETEROGENEOUS */
  1700. X    if (_send_data_encoded(&con_port, (char *) &locinfo, xdr_ADMINLOCINFO, CPTOAPSNDTIME) < 0) {
  1701. X#endif /* SINGLE || HOMOGENEOUS /**/
  1702. X        if (Errno == ETIMEOUT)
  1703. X            Errno = ETCCPTOAPSND;;
  1704. X        return(ERROR);
  1705. X    }
  1706. X    DEBUGPUTS("receiving hostname");
  1707. X#if defined(SINGLE) || defined(HOMOGENEOUS)
  1708. X    if (_recv_data(&con_port, (char *) &locinfo, sizeof(ADMINLOCINFO), CPTOAPRCVTIME) < 0) {
  1709. X#else /* HETEROGENEOUS */
  1710. X    if (_recv_data_encoded(&con_port, (char *) &locinfo, xdr_ADMINLOCINFO, CPTOAPRCVTIME)) {
  1711. X#endif /* HETEROGENEOUS /**/
  1712. X    if (Errno == ETIMEOUT)
  1713. X        Errno = ETCCPTOAPRCV;
  1714. X    _close_connection(&con_port);
  1715. X    return(ERROR);
  1716. X    }
  1717. X    _close_connection(&con_port);
  1718. X    *location = locinfo.hostname;
  1719. X    Errno = -1;
  1720. X    return(OK);
  1721. X} /* _get_location_from_admin */
  1722. END_OF_FILE
  1723. if test 35757 -ne `wc -c <'lib/creation.c'`; then
  1724.     echo shar: \"'lib/creation.c'\" unpacked with wrong size!
  1725. fi
  1726. # end of 'lib/creation.c'
  1727. fi
  1728. echo shar: End of archive 15 \(of 18\).
  1729. cp /dev/null ark15isdone
  1730. MISSING=""
  1731. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1732.     if test ! -f ark${I}isdone ; then
  1733.     MISSING="${MISSING} ${I}"
  1734.     fi
  1735. done
  1736. if test "${MISSING}" = "" ; then
  1737.     echo You have unpacked all 18 archives.
  1738.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1739. else
  1740.     echo You still need to unpack the following archives:
  1741.     echo "        " ${MISSING}
  1742. fi
  1743. ##  End of shell archive.
  1744. exit 0
  1745.