File: unparse_job_cull.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 56,756 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,934; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361
file content (798 lines) | stat: -rw-r--r-- 23,824 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/
/*___INFO__MARK_END__*/
#include <string.h>

#include "uti/sge_rmon.h"
#include "uti/sge_string.h"
#include "uti/sge_hostname.h"
#include "uti/sge_language.h"
#include "uti/sge_dstring.h"

#include "sgeobj/sge_ja_task.h"
#include "sgeobj/sge_str.h"
#include "sgeobj/sge_pe.h"
#include "sgeobj/sge_qinstance.h"
#include "sgeobj/parse.h"
#include "sgeobj/cull_parse_util.h"
#include "sgeobj/sge_var.h"
#include "sgeobj/sge_answer.h" 
#include "sgeobj/sge_feature.h"
#include "sgeobj/sge_range.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_userset.h"
#include "sgeobj/sge_mailrec.h"
#include "sgeobj/sge_centry.h"
#include "sgeobj/sge_qref.h"

#include "sched/valid_queue_user.h"

#include "parse_qsub.h"
#include "parse_job_cull.h"
#include "unparse_job_cull.h"
#include "sge.h"
#include "symbols.h"
#include "sge_options.h"
#include "msg_daemons_common.h"


static char *sge_unparse_checkpoint_attr(int opr, char *string);
/* static char *sge_unparse_hold_list(u_long32 hold); */
static char *sge_unparse_mail_options(u_long32 mail_opt);
static int sge_unparse_checkpoint_option(lListElem *job, lList **pcmdline, lList **alpp);
static int sge_unparse_account_string(lListElem *job, lList **pcmdline, lList **alpp);
static int sge_unparse_path_list(lListElem *job, int nm, char *option, lList **pcmdline, lList **alpp);
static int sge_unparse_pe(lListElem *job, lList **pcmdline, lList **alpp);

static int sge_unparse_resource_list(lListElem *job, int nm, lList **pcmdline, lList **alpp);
static int sge_unparse_string_option(lListElem *job, int nm, char *option, lList **pcmdline, lList **alpp);

lList *cull_unparse_job_parameter(sge_gdi_ctx_class_t *ctx, lList **pcmdline, lListElem *job, int flags)
{
   const char *cp;
   u_long32 ul;
   lList *answer = NULL;
   char str[MAX_STRING_SIZE];
   lList *lp;
   int ret;
   lListElem *ep_opt;
   const char *username = ctx->get_username(ctx);
   const char *qualified_hostname = ctx->get_qualified_hostname(ctx);

   DENTER(TOP_LAYER, "cull_unparse_job_parameter");

   /*
   ** -a
   ** problem with submission time, but that is not a good
   ** default option anyway, is not unparsed
   */

   /*
   ** -A
   */
   if (sge_unparse_account_string(job, pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }

   /*
   ** -c
   */
   if (sge_unparse_checkpoint_option(job, pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }
  
   /*
    * -ckpt 
    */
   if (sge_unparse_string_option(job, JB_checkpoint_name, "-ckpt", 
            pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }


   /*
   ** -cwd
   */
   if (lGetString(job, JB_cwd)) {
      ep_opt = sge_add_noarg(pcmdline, cwd_OPT, "-cwd", NULL);
   }

   /*
    * -P
    */
   if (sge_unparse_string_option(job, JB_project, "-P",
            pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }

#if 0
   /*
   ** -C
   */
   if (sge_unparse_string_option(job, JB_directive_prefix, "-C", 
            pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }
#endif   

   /*
   ** -e
   */
   if (sge_unparse_path_list(job, JB_stderr_path_list, "-e", pcmdline, 
                     &answer) != 0) {
      DEXIT;
      return answer;
   }

   /*
   ** -h, here only user hold supported at the moment
   */
   if  ((ul = lGetUlong(lFirst(lGetList(job, JB_ja_tasks)), JAT_hold))) {
      ep_opt = sge_add_noarg(pcmdline, h_OPT, "-h", NULL);
   }

   /*
   ** -hold_jid
   */
   if ((lp = lGetList(job, JB_jid_request_list))) {
      int fields[] = { JRE_job_name, 0 };
      const char *delis[] = {NULL, ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 0);
      if (ret) {
         DPRINTF(("Error %d formatting jid_request_list as -hold_jid\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGJIDPREDECESSORLISTASHOLDJID);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, hold_jid_OPT, lListT, "-hold_jid", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("hold_jid list", lp));      
   }

   /*
   ** -hold_jid_ad
   */
   if ((lp = lGetList(job, JB_ja_ad_request_list))) {
      int fields[] = { JRE_job_name, 0 };
      const char *delis[] = {NULL, ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 0);
      if (ret) {
         DPRINTF(("Error %d formatting ja_ad_request_list as -hold_jid_ad\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGJIDPREDECESSORLISTASHOLDJIDAD);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, hold_jid_ad_OPT, lListT, "-hold_jid_ad", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("hold_jid_ad list", lp));      
   }

   /*
   ** -i
   */
   if (sge_unparse_path_list(job, JB_stdin_path_list, "-i", pcmdline, 
                     &answer) != 0) {
      DEXIT;
      return answer;
   }

   /*
   ** -j
   */
   if ((ul = lGetBool(job, JB_merge_stderr))) {
      ep_opt = sge_add_arg(pcmdline, j_OPT, lIntT, "-j", "y");
      lSetInt(ep_opt, SPA_argval_lIntT, true);
   }
   
   /*
   ** -jid
   */
   if ((lp = lGetList(job, JB_job_identifier_list))) {
      int fields[] = { JRE_job_number, 0};
      const char *delis[] = {"", ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 
         0);
      if (ret) {
         DPRINTF(("Error %d formatting job_identifier_list as -jid\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGJOBIDENTIFIERLISTASJID);
         DRETURN(answer);
      }
      ep_opt = sge_add_arg(pcmdline, jid_OPT, lListT, "-jid", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("jid list", lp));      
   }

   /*
   ** -js
   */
   if ((ul = lGetUlong(job, JB_jobshare)) != 0)  {
      sprintf(str, sge_u32, ul);
      ep_opt = sge_add_arg(pcmdline, js_OPT, lUlongT, "-js", str);
      lSetUlong(ep_opt, SPA_argval_lUlongT, ul);
   }

   /*
   ** -lj is in parsing but can't be unparsed here
   */

   /*
   ** -l
   */
   if (sge_unparse_resource_list(job, JB_hard_resource_list,
            pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }
   if (sge_unparse_resource_list(job, JB_soft_resource_list,
            pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }






   /*
   ** -m
   */
   if ((ul = lGetUlong(job, JB_mail_options))) {
      cp = sge_unparse_mail_options(ul);
      if (!cp) {
         DPRINTF(("Error unparsing mail options\n"));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_PARSE_ERRORUNPARSINGMAILOPTIONS);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, m_OPT, lIntT, "-m", cp);
      lSetInt(ep_opt, SPA_argval_lIntT, ul);
   }

   /*
   ** -M obviously a problem!!!
   ** not unparsed at the moment
   ** does it make sense as a default, after all?
   */
   if ((lp = lGetList(job, JB_mail_list))) {
      lList *lp_new = NULL;
      lListElem *ep_new = NULL;
      lListElem *ep = NULL;
      const char *host;
      const char *user;

      /*
      ** or rather take all if there are more than one elements?
      */
      for_each(ep, lp) {
         user = lGetString(ep, MR_user);
         host = lGetHost(ep, MR_host);
         if (sge_strnullcmp(user, username) || 
             sge_hostcmp(host, qualified_hostname)) {
            lp_new = lCreateList("mail list", MR_Type);
            ep_new = lAddElemStr(&lp_new, MR_user, user, MR_Type);
            lSetHost(ep_new, MR_host, host);
         }
      }
      if (lp_new) {
         int fields[] = { MR_user, MR_host, 0 };
         const char *delis[] = {"@", ",", NULL};

         ret = uni_print_list(NULL, str, sizeof(str) - 1, lp_new, fields, delis, FLG_NO_DELIS_STRINGS);
         if (ret) {
            DPRINTF(("Error %d formatting mail list as -M\n", ret));
            answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                    "%s", MSG_LIST_ERRORFORMATTINGMAILLISTASM);
            return answer;
         }
         ep_opt = sge_add_arg(pcmdline, M_OPT, lListT, "-M", str);
         lSetList(ep_opt, SPA_argval_lListT, lp_new);
 
      }
   }

   /*
   ** -N
   ** dont unparse the job name!
   ** each job has a jobname, but not each defaults file wants a -N
   */
#if 0
   if ((cp = lGetString(job, JB_job_name))) {
      ep_opt = sge_add_arg(pcmdline, N_OPT, lStringT, "-N", cp);
      lSetString(ep_opt, SPA_argval_lStringT, cp);
   }
#endif
   /*
   ** -notify
   */
   if  ((ul = lGetBool(job, JB_notify))) {
      ep_opt = sge_add_noarg(pcmdline, notify_OPT, "-notify", NULL);
   }

   /*
   ** -o
   */
   if (sge_unparse_path_list(job, JB_stdout_path_list, "-o", pcmdline, 
                     &answer) != 0) {
      DEXIT;
      return answer;
   }

   /*
   ** -p
   */
   if ((ul = lGetUlong(job, JB_priority)) != BASE_PRIORITY)  {
      int prty;

      prty = ul - BASE_PRIORITY;
      if (prty > 1024) {
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_PROC_INVALIDPROIRITYMUSTBELESSTHAN1025);
         DEXIT;
         return answer;
      }
      if (prty < -1023) {
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_PROC_INVALIDPRIORITYMUSTBEGREATERTHANMINUS1024);
         DEXIT;
         return answer;
      }
      sprintf(str, "%d", prty);
      ep_opt = sge_add_arg(pcmdline, p_OPT, lIntT, "-p", str);
      lSetInt(ep_opt, SPA_argval_lIntT, prty);
   }

   /*
   ** -pe
   */
   if (sge_unparse_pe(job, pcmdline, &answer) != 0) {
      DEXIT;
      return answer;
   }


#if 1
   /*
   ** -q
   ** exec-string is suppressed because uni_print_list can't do this
   ** is not in the manual anyway
   */
   if ((lp = lGetList(job, JB_hard_queue_list))) {
      int fields[] = { QR_name, 0 };
      const char *delis[] = {"@", ",", NULL};

      ep_opt = sge_add_noarg(pcmdline, hard_OPT, "-hard", NULL);
      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 
         FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting hard_queue_list as -q\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGHARDQUEUELISTASQ);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, q_OPT, lListT, "-q", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("hard queue list", lp));      
      lSetInt(ep_opt, SPA_argval_lIntT, 1); /* means hard */
   }
   if ((lp = lGetList(job, JB_soft_queue_list))) {
      int fields[] = { QR_name, 0 };
      const char *delis[] = {"@", ",", NULL};

      ep_opt = sge_add_noarg(pcmdline, soft_OPT, "-soft", NULL);
      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 
         FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting soft_queue_list as -q\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGSOFTQUEUELISTASQ);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, q_OPT, lListT, "-q", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("soft queue list", lp));      
      lSetInt(ep_opt, SPA_argval_lIntT, 2); /* means soft */
   }
#endif
   
   /*
   ** -R
   */
   if ((ul = lGetBool(job, JB_reserve))) {
      ep_opt = sge_add_arg(pcmdline, R_OPT, lIntT, "-R", "y");
      lSetInt(ep_opt, SPA_argval_lIntT, true);
   }

   /*
   ** -r
   */
   if ((lGetUlong(job, JB_restart) == 1)) {
      ep_opt = sge_add_arg(pcmdline, r_OPT, lIntT, "-r", "y");
      lSetInt(ep_opt, SPA_argval_lIntT, 1);
   } else if ((lGetUlong(job, JB_restart) == 2)) {
      ep_opt = sge_add_arg(pcmdline, r_OPT, lIntT, "-r", "n");
      lSetInt(ep_opt, SPA_argval_lIntT, 2);
   }

   /*
   ** -S
   */
#if 1   
   if (sge_unparse_path_list(job, JB_shell_list, "-S", pcmdline, 
                     &answer) != 0) {
      DEXIT;
      return answer;
   }
#else
   if ((lp = lGetList(job, JB_shell_list))) {
      int fields[] = { PN_host, PN_file_host, PN_path, PN_file_staging, 0 };
      const char *delis[] = {":", ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting shell_list\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 MSG_LIST_ERRORFORMATINGSHELLLIST);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, S_OPT, lListT, "-S", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("shell list", lp));
   }
#endif

   /*
   ** -v, -V
   ** we always generate a -v statement, which means the user should not
   ** declare a job generated with -V as default
   */
   if ((lp = lGetList(job, JB_env_list))) {
      int fields[] = { VA_variable, VA_value, 0};
      const char *delis[] = {"=", ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 
         FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting environment list as -v\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGENVIRONMENTLISTASV);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, v_OPT, lListT, "-v", str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("env list", lp));      
   }

   /*
   ** -verify is not unparsed
   */

   /*
   ** for full cmdline, script is needed
   */
   if ((flags & FLG_FULL_CMDLINE) &&
      (cp = lGetString(job, JB_script_file))) {
      if (!strcmp(cp, "STDIN")) {
         if (lGetList(job, JB_job_args)) {
         ep_opt = sge_add_arg(pcmdline, 0, lStringT, STR_PSEUDO_SCRIPT, "--");
         lSetString(ep_opt, SPA_argval_lStringT, "--");
         }
      }
      else {
      }
   }

   /*
   ** for full cmdline, job args are also needed
   */
   if ((flags & FLG_FULL_CMDLINE) &&
      (lp = lGetList(job, JB_job_args))) {
      int fields[] = { ST_name, 0};
      const char *delis[] = {NULL, " ", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 
         FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting job arguments\n", ret));
         answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGJOBARGUMENTS);
         return answer;
      }
      ep_opt = sge_add_arg(pcmdline, 0, lListT, STR_PSEUDO_JOBARG, str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("job arguments", lp));      
   }




   DEXIT;
   return answer;
}


static char *sge_unparse_checkpoint_attr(int opr, char *str)
{
   int i = 0;

   if (opr & CHECKPOINT_AT_MINIMUM_INTERVAL)
      str[i++] = CHECKPOINT_AT_MINIMUM_INTERVAL_SYM;
   if (opr & CHECKPOINT_AT_SHUTDOWN)
      str[i++] = CHECKPOINT_AT_SHUTDOWN_SYM;
   if (opr & CHECKPOINT_SUSPEND)
      str[i++] = CHECKPOINT_SUSPEND_SYM;
   if (opr & NO_CHECKPOINT)
      str[i++] = NO_CHECKPOINT_SYM;

   str[i] = '\0';

   return str;
}

/*-------------------------------------------------------------------------*/
static char *sge_unparse_mail_options(
u_long32 mail_opt 
) {
   static char mail_str[5 + 1];
   char *pc;

   DENTER(TOP_LAYER, "sge_unparse_mail_options");

   memset(mail_str, 0, sizeof(mail_str));
   pc = mail_str;
   if (VALID(MAIL_AT_ABORT, mail_opt)) {
      *pc++ = 'a';
   }
   if (VALID(MAIL_AT_BEGINNING, mail_opt)) {
      *pc++ = 'b';
   }
   if (VALID(MAIL_AT_EXIT, mail_opt)) {
      *pc++ = 'e';
   }
   if (VALID(NO_MAIL, mail_opt)) {
      *pc++ = 'n';
   }
   if (VALID(MAIL_AT_SUSPENSION, mail_opt)) {
      *pc++ = 's';
   }
   
   if  (!*mail_str) {
      DEXIT;
      return NULL;
   }

   DEXIT;
   return (mail_str);
}

/*-------------------------------------------------------------------------*/
static int sge_unparse_account_string(
lListElem *job,
lList **pcmdline,
lList **alpp 
) {
   const char *cp;
   lListElem *ep_opt;

   DENTER(TOP_LAYER, "sge_unparse_account_string");
   
   if ((cp = lGetString(job, JB_account))) {
      if (strcmp(cp, DEFAULT_ACCOUNT)) {
         ep_opt = sge_add_arg(pcmdline, A_OPT, lStringT, "-A", cp);
         lSetString(ep_opt, SPA_argval_lStringT, cp);
      }
   }
   DEXIT;
   return 0;
}


/*-------------------------------------------------------------------------*/
static int sge_unparse_checkpoint_option(lListElem *job, lList **pcmdline, lList **alpp)
{
   lListElem *ep_opt = NULL;
   char *cp;
   int i;
   u_long32 ul;
   char str[256];

   DENTER(TOP_LAYER, "sge_unparse_checkpoint_option");

   if ((i = lGetUlong(job, JB_checkpoint_attr))) {
      if ((cp = sge_unparse_checkpoint_attr(i, str))) {
         ep_opt = sge_add_arg(pcmdline, 0, lIntT, "-c", cp);
         lSetInt(ep_opt, SPA_argval_lIntT, i);
      } else {
         answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 MSG_JOB_INVALIDVALUEFORCHECKPOINTATTRIBINJOB_U,
                                 sge_u32c(lGetUlong(job, JB_job_number)));
         DRETURN(-1);
      }
   }

   if ((ul = lGetUlong(job, JB_checkpoint_interval))) {
      snprintf(str, sizeof(str), sge_uu32, ul);
      ep_opt = sge_add_arg(pcmdline, c_OPT, lLongT, "-c", str);
      lSetLong(ep_opt, SPA_argval_lLongT, (long) ul);
   }

   DRETURN(0);
}


/*-------------------------------------------------------------------------*/
static int sge_unparse_string_option(
lListElem *job,
int nm,
char *option,
lList **pcmdline,
lList **alpp 
) {
   lListElem *ep_opt = NULL;
   const char *cp;

   DENTER(TOP_LAYER, "sge_unparse_string_option");
   
   if ((cp = lGetString(job, nm))) {
      ep_opt = sge_add_arg(pcmdline, 0, lStringT, option, cp);
      lSetString(ep_opt, SPA_argval_lStringT, cp);
   }
   DEXIT;
   return 0;
}


/*-------------------------------------------------------------------------*/
static int sge_unparse_resource_list(lListElem *job, int nm, lList **pcmdline, lList **alpp)
{
   lList *lp;
   int ret = 0;
   char str[MAX_STRING_SIZE];

   DENTER(TOP_LAYER, "sge_unparse_resource_list");

   if ((lp = lGetList(job, nm))) {
      lListElem *ep_opt;
      int hard = (nm == JB_hard_resource_list);

      if (hard) {
         ep_opt = sge_add_noarg(pcmdline, hard_OPT, "-hard", NULL);
      }
      else {
         ep_opt = sge_add_noarg(pcmdline, soft_OPT, "-soft", NULL);
      }

      ret = centry_list_append_to_string(lp, str, sizeof(str) - 1);
      if (ret) {
         DPRINTF(("Error %d formatting hard_resource_list as -l\n", ret));
         answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGHARDRESOURCELISTASL);
         return ret;
      }
      if (*str && (str[strlen(str) - 1] == '\n')) {
         str[strlen(str) - 1] = 0;
      }
      ep_opt = sge_add_arg(pcmdline, l_OPT, lListT, "-l", str);

      if (hard)
         lSetList(ep_opt, SPA_argval_lListT, lCopyList("hard res", lp));
      else
         lSetList(ep_opt, SPA_argval_lListT, lCopyList("soft res", lp));

      if (hard) 
         lSetInt(ep_opt, SPA_argval_lIntT, 1); /* means hard */
      else
         lSetInt(ep_opt, SPA_argval_lIntT, 2); /* means soft */
   }
   DEXIT;
   return ret;
}

/*-------------------------------------------------------------------------*/
static int sge_unparse_pe(
lListElem *job,
lList **pcmdline,
lList **alpp 
) {
   const char *cp;
   lList *lp = NULL;
   lListElem *ep_opt;
   dstring string_buffer = DSTRING_INIT;
   int ret = 0;

   DENTER(TOP_LAYER, "sge_unparse_pe");

   if ((cp = lGetString(job, JB_pe))) {
      sge_dstring_append(&string_buffer, cp);
      sge_dstring_append(&string_buffer, " ");
      if (!(lp = lGetList(job, JB_pe_range))) {
         DPRINTF(("Job has parallel environment with no ranges\n"));
         answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_JOB_JOBHASPEWITHNORANGES);
         sge_dstring_free(&string_buffer);
         DEXIT;
         return -1;
      }
      {
         dstring range_string = DSTRING_INIT;

         range_list_print_to_string(lp, &range_string, true, false, false);
         sge_dstring_append(&string_buffer, 
                            sge_dstring_get_string(&range_string));
         sge_dstring_free(&range_string);
      }
      if (ret) {
         DPRINTF(("Error %d formatting ranges in -pe\n", ret));
         answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGRANGESINPE);
         sge_dstring_free(&string_buffer);
         DEXIT;
         return ret;
      }
      ep_opt = sge_add_arg(pcmdline, pe_OPT, lStringT, "-pe", 
                           sge_dstring_get_string(&string_buffer));
      lSetString(ep_opt, SPA_argval_lStringT, cp);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList("pe ranges", lp));
   }
   sge_dstring_free(&string_buffer);
   DEXIT;
   return ret;
}

/*-------------------------------------------------------------------------*/
static int sge_unparse_path_list(lListElem *job, int nm, char *option, lList **pcmdline, lList **alpp)
{
   lList *lp = NULL;
   int ret = 0;
   char str[MAX_STRING_SIZE];
   lListElem *ep_opt;

   DENTER(TOP_LAYER, "sge_unparse_path_list");

   if ((lp = lGetList(job, nm))) {
      int fields[] = { PN_host, PN_path, 0 };
      const char *delis[] = {":", ",", NULL};

      ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, FLG_NO_DELIS_STRINGS);
      if (ret) {
         DPRINTF(("Error %d formatting path_list\n", ret));
         answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                 "%s", MSG_LIST_ERRORFORMATINGPATHLIST);
         return ret;
      }
      ep_opt = sge_add_arg(pcmdline, e_OPT, lListT, option, str);
      lSetList(ep_opt, SPA_argval_lListT, lCopyList(option, lp));
   }
   DEXIT;
   return ret;
}