]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/autochanger.c
Get correct slot when auto unloading a device.
[bacula/bacula] / bacula / src / stored / autochanger.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *  Routines for handling the autochanger.
31  *
32  *   Kern Sibbald, August MMII
33  *                            
34  *   Version $Id$
35  */
36
37 #include "bacula.h"                   /* pull in global headers */
38 #include "stored.h"                   /* pull in Storage Deamon headers */
39
40 /* Forward referenced functions */
41 static void lock_changer(DCR *dcr);
42 static void unlock_changer(DCR *dcr);
43 static bool unload_other_drive(DCR *dcr, int slot);
44
45 /* Init all the autochanger resources found */
46 bool init_autochangers()
47 {
48    bool OK = true;
49    AUTOCHANGER *changer;
50    /* Ensure that the media_type for each device is the same */
51    foreach_res(changer, R_AUTOCHANGER) {
52       DEVRES *device;
53       foreach_alist(device, changer->device) {
54          /*
55           * If the device does not have a changer name or changer command
56           *   defined, used the one from the Autochanger resource 
57           */
58          if (!device->changer_name && changer->changer_name) {
59             device->changer_name = bstrdup(changer->changer_name);
60          }
61          if (!device->changer_command && changer->changer_command) {
62             device->changer_command = bstrdup(changer->changer_command);
63          }
64          if (!device->changer_name) {
65             Jmsg(NULL, M_ERROR, 0, 
66                _("No Changer Name given for device %s. Cannot continue.\n"),
67                device->hdr.name);
68             OK = false;
69          }   
70          if (!device->changer_command) {
71             Jmsg(NULL, M_ERROR, 0, 
72                _("No Changer Command given for device %s. Cannot continue.\n"),
73                device->hdr.name);
74             OK = false;
75          }   
76
77 #ifdef xxx_needed
78          if (media_type == NULL) {
79             media_type = device->media_type;     /* get Media Type of first device */
80             continue;
81          }     
82          /* Ensure that other devices Media Types are the same */
83          if (strcmp(media_type, device->media_type) != 0) {
84             Jmsg(NULL, M_ERROR, 0, 
85                _("Media Type not the same for all devices in changer %s. Cannot continue.\n"),
86                changer->hdr.name);
87             OK = false;
88             continue;
89          }
90 #endif
91       }
92    }
93    return OK;
94 }
95
96
97 /*
98  * Called here to do an autoload using the autochanger, if
99  *  configured, and if a Slot has been defined for this Volume.
100  *  On success this routine loads the indicated tape, but the
101  *  label is not read, so it must be verified.
102  *
103  *  Note if dir is not NULL, it is the console requesting the
104  *   autoload for labeling, so we respond directly to the
105  *   dir bsock.
106  *
107  *  Returns: 1 on success
108  *           0 on failure (no changer available)
109  *          -1 on error on autochanger
110  */
111 int autoload_device(DCR *dcr, int writing, BSOCK *dir)
112 {
113    JCR *jcr = dcr->jcr;
114    DEVICE * volatile dev = dcr->dev;
115    int slot;
116    int drive = dev->drive_index;
117    int rtn_stat = -1;                 /* error status */
118    POOLMEM *changer;
119
120    if (!dev->is_autochanger()) {
121       Dmsg1(100, "Device %s is not an autochanger\n", dev->print_name());
122       return 0;
123    }
124
125    /* An empty ChangerCommand => virtual disk autochanger */
126    if (dcr->device->changer_command && dcr->device->changer_command[0] == 0) {
127       Dmsg0(100, "ChangerCommand=0, virtual disk changer\n");
128       return 1;                       /* nothing to load */
129    }
130
131    slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
132    Dmsg3(100, "autoload: slot=%d InChgr=%d Vol=%s\n", dcr->VolCatInfo.Slot,
133          dcr->VolCatInfo.InChanger, dcr->VolCatInfo.VolCatName);
134    /*
135     * Handle autoloaders here.  If we cannot autoload it, we
136     *  will return 0 so that the sysop will be asked to load it.
137     */
138    if (writing && slot <= 0) {
139       if (dir) {
140          return 0;                    /* For user, bail out right now */
141       }
142       /* ***FIXME*** this really should not be here */
143       if (dir_find_next_appendable_volume(dcr)) {
144          slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
145       } else {
146          slot = 0;
147       }
148    }
149    Dmsg1(400, "Want changer slot=%d\n", slot);
150
151    changer = get_pool_memory(PM_FNAME);
152    if (slot <= 0) {
153       Jmsg(jcr, M_INFO, 0, _("Invalid slot=%d defined in catalog for Volume \"%s\" "
154            "on %s. Manual load may be required.\n"), slot, dcr->VolCatInfo.VolCatName,
155            dev->print_name());
156       rtn_stat = 0;
157    } else if (!dcr->device->changer_name) {
158       Jmsg(jcr, M_INFO, 0, _("No \"Changer Device\" for %s. Manual load of Volume may be required.\n"),
159            dev->print_name());
160       rtn_stat = 0;
161   } else if (!dcr->device->changer_command) {
162       Jmsg(jcr, M_INFO, 0, _("No \"Changer Command\" for %s. Manual load of Volume may be requird.\n"),
163            dev->print_name());
164       rtn_stat = 0;
165   } else {
166       /* Attempt to load the Volume */
167
168       uint32_t timeout = dcr->device->max_changer_wait;
169       int loaded, status;
170
171       loaded = get_autochanger_loaded_slot(dcr);
172
173       if (loaded != slot) {
174          POOL_MEM results(PM_MESSAGE);
175
176          /* Unload anything in our drive */
177          if (!unload_autochanger(dcr, loaded)) {
178             goto bail_out;
179          }
180             
181          /* Make sure desired slot is unloaded */
182          if (!unload_other_drive(dcr, slot)) {
183             goto bail_out;
184          }
185
186          /*
187           * Load the desired cassette
188           */
189          lock_changer(dcr);
190          Dmsg2(100, "Doing changer load slot %d %s\n", slot, dev->print_name());
191          Jmsg(jcr, M_INFO, 0,
192               _("3304 Issuing autochanger \"load slot %d, drive %d\" command.\n"),
193               slot, drive);
194          dcr->VolCatInfo.Slot = slot;    /* slot to be loaded */
195          changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "load");
196          dev->close();
197          Dmsg1(200, "Run program=%s\n", changer);
198          status = run_program_full_output(changer, timeout, results.addr());
199          if (status == 0) {
200             Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
201                     slot, drive);
202             Dmsg2(100, "load slot %d, drive %d, status is OK.\n", slot, drive);
203             dev->set_slot(slot);      /* set currently loaded slot */
204          } else {
205             berrno be;
206             be.set_errno(status);
207             Dmsg3(100, "load slot %d, drive %d, bad stats=%s.\n", slot, drive,
208                be.bstrerror());
209             Jmsg(jcr, M_FATAL, 0, _("3992 Bad autochanger \"load slot %d, drive %d\": "
210                  "ERR=%s.\nResults=%s\n"),
211                     slot, drive, be.bstrerror(), results.c_str());
212             rtn_stat = -1;            /* hard error */
213             dev->set_slot(-1);        /* mark unknown */
214          }
215          Dmsg2(100, "load slot %d status=%d\n", slot, status);
216          unlock_changer(dcr);
217       } else {
218          status = 0;                  /* we got what we want */
219          dev->set_slot(slot);         /* set currently loaded slot */
220       }
221       Dmsg1(100, "After changer, status=%d\n", status);
222       if (status == 0) {              /* did we succeed? */
223          rtn_stat = 1;                /* tape loaded by changer */
224       }
225    }
226    free_pool_memory(changer);
227    return rtn_stat;
228
229 bail_out:
230    free_pool_memory(changer);
231    return -1;
232
233 }
234
235 /*
236  * Returns: -1 if error from changer command
237  *          slot otherwise
238  *  Note, this is safe to do without releasing the drive
239  *   since it does not attempt load/unload a slot.
240  */
241 int get_autochanger_loaded_slot(DCR *dcr)
242 {
243    JCR *jcr = dcr->jcr;
244    DEVICE *dev = dcr->dev;
245    int status, loaded;
246    uint32_t timeout = dcr->device->max_changer_wait;
247    int drive = dcr->dev->drive_index;
248    POOL_MEM results(PM_MESSAGE);
249    POOLMEM *changer;
250
251    if (!dev->is_autochanger()) {
252       return -1;
253    }
254    if (!dcr->device->changer_command) {
255 //    Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n"));
256       return -1;
257    }
258    if (dev->get_slot() > 0) {
259       return dev->get_slot();
260    }
261
262    /* Virtual disk autochanger */
263    if (dcr->device->changer_command[0] == 0) {
264       return 1;
265    }
266
267    /* Find out what is loaded, zero means device is unloaded */
268    changer = get_pool_memory(PM_FNAME);
269    lock_changer(dcr);
270    Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded? drive %d\" command.\n"),
271         drive);
272    changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "loaded");
273    Dmsg1(100, "Run program=%s\n", changer);
274    status = run_program_full_output(changer, timeout, results.addr());
275    Dmsg3(100, "run_prog: %s stat=%d result=%s", changer, status, results.c_str());
276    if (status == 0) {
277       loaded = str_to_int32(results.c_str());
278       if (loaded > 0) {
279          Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded? drive %d\", result is Slot %d.\n"),
280               drive, loaded);
281          dev->set_slot(loaded);
282       } else {
283          Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded? drive %d\", result: nothing loaded.\n"),
284               drive);
285          dev->clear_slot();   /* unknown */
286       }
287    } else {
288       berrno be;
289       be.set_errno(status);
290       Jmsg(jcr, M_INFO, 0, _("3991 Bad autochanger \"loaded? drive %d\" command: "
291            "ERR=%s.\nResults=%s\n"), drive, be.bstrerror(), results.c_str());
292       loaded = -1;              /* force unload */
293    }
294    unlock_changer(dcr);
295    free_pool_memory(changer);
296    return loaded;
297 }
298
299 static void lock_changer(DCR *dcr)
300 {
301    AUTOCHANGER *changer_res = dcr->device->changer_res;
302    if (changer_res) {
303       Dmsg1(200, "Locking changer %s\n", changer_res->hdr.name);
304       P(changer_res->changer_mutex);  /* Lock changer script */
305    }
306 }
307
308 static void unlock_changer(DCR *dcr)
309 {
310    AUTOCHANGER *changer_res = dcr->device->changer_res;
311    if (changer_res) {
312       Dmsg1(200, "Unlocking changer %s\n", changer_res->hdr.name);
313       V(changer_res->changer_mutex);  /* Unlock changer script */
314    }
315 }
316
317 /*
318  * Unload the volume, if any, in this drive
319  *  On entry: loaded == 0 -- nothing to do
320  *            loaded  < 0 -- check if anything to do
321  *            loaded  > 0 -- load slot == loaded
322  */
323 bool unload_autochanger(DCR *dcr, int loaded)
324 {
325    DEVICE *dev = dcr->dev;
326    JCR *jcr = dcr->jcr;
327    int slot;
328    uint32_t timeout = dcr->device->max_changer_wait;
329    bool ok = true;
330
331    if (loaded == 0) {
332       return true;
333    }
334
335    if (!dev->is_autochanger() || !dcr->device->changer_name ||
336        !dcr->device->changer_command) {
337       return false;
338    }
339
340    /* Virtual disk autochanger */
341    if (dcr->device->changer_command[0] == 0) {
342       dev->clear_unload();
343       return true;
344    }
345
346    if (loaded < 0) {
347       loaded = get_autochanger_loaded_slot(dcr);
348    }
349
350    if (loaded > 0) {
351       POOL_MEM results(PM_MESSAGE);
352       POOLMEM *changer = get_pool_memory(PM_FNAME);
353       lock_changer(dcr);
354       Jmsg(jcr, M_INFO, 0,
355            _("3307 Issuing autochanger \"unload slot %d, drive %d\" command.\n"),
356            loaded, dev->drive_index);
357       slot = dcr->VolCatInfo.Slot;
358       dcr->VolCatInfo.Slot = loaded;
359       changer = edit_device_codes(dcr, changer, 
360                    dcr->device->changer_command, "unload");
361       dev->close();
362       Dmsg1(100, "Run program=%s\n", changer);
363       int stat = run_program_full_output(changer, timeout, results.addr());
364       dcr->VolCatInfo.Slot = slot;
365       if (stat != 0) {
366          berrno be;
367          be.set_errno(stat);
368          Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d, drive %d\": "
369               "ERR=%s\nResults=%s\n"),
370                  loaded, dev->drive_index, be.bstrerror(), results.c_str());
371          ok = false;
372          dev->clear_slot();        /* unknown */
373       } else {
374          dev->set_slot(0);         /* nothing loaded */
375       }
376       unlock_changer(dcr);
377
378       free_volume(dev);            /* Free any volume associated with this drive */
379       free_pool_memory(changer);
380    }
381    dev->clear_unload();
382    return ok;
383 }
384
385 /*
386  * Unload the slot if mounted in a different drive
387  */
388 static bool unload_other_drive(DCR *dcr, int slot)
389 {
390    DEVICE *dev = NULL;
391    bool found = false;
392    AUTOCHANGER *changer = dcr->dev->device->changer_res;
393    DEVRES *device;
394    int retries = 0;                /* wait for device retries */
395
396    if (!changer) {
397       return false;
398    }
399    if (changer->device->size() == 1) {
400       return true;
401    }
402
403    foreach_alist(device, changer->device) {
404       if (device->dev && device->dev->get_slot() == slot) {
405          found = true;
406          dev = device->dev;
407          break;
408       }
409    }
410    if (!found) {
411       return true;
412    }
413
414    /* The Volume we want is on another device. */
415    if (dev->is_busy()) {
416       Dmsg4(100, "Vol %s for dev=%s in use dev=%s slot=%d\n",
417            dcr->VolumeName, dcr->dev->print_name(),
418            dev->print_name(), slot);
419    }   
420    for (int i=0; i < 3; i++) {
421       if (dev->is_busy()) {
422          wait_for_device(dcr->jcr, retries);
423          continue;
424       }
425       break;
426    }
427    if (dev->is_busy()) {
428       Jmsg(dcr->jcr, M_WARNING, 0, _("Volume \"%s\" is in use by device %s\n"),
429            dcr->VolumeName, dev->print_name());
430       Dmsg4(100, "Vol %s for dev=%s is busy dev=%s slot=%d\n",
431            dcr->VolumeName, dcr->dev->print_name(), dev->print_name(), dev->get_slot());
432       Dmsg2(100, "num_writ=%d reserv=%d\n", dev->num_writers, dev->num_reserved());
433       return false;
434    }
435    return unload_dev(dcr, dev);
436 }
437
438 /*
439  * Unconditionally unload a specified drive
440  */
441 bool unload_dev(DCR *dcr, DEVICE *dev)
442 {
443    JCR *jcr = dcr->jcr;
444    bool ok = true;
445    uint32_t timeout = dcr->device->max_changer_wait;
446    AUTOCHANGER *changer = dcr->dev->device->changer_res;
447    DEVICE *save_dev;
448    int save_slot;
449
450    if (!changer) {
451       return false;
452    }
453
454    save_dev = dcr->dev;               /* save dcr device */
455    dcr->dev = dev;                    /* temporarily point dcr at other device */
456    save_slot = dcr->VolCatInfo.Slot;
457
458    if (dev->get_slot() <= 0 && get_autochanger_loaded_slot(dcr) <= 0) {
459       dcr->VolCatInfo.Slot = save_slot;
460       dcr->dev = save_dev;
461       return false;
462    }
463    dcr->VolCatInfo.Slot = dev->get_slot();
464
465    dev->dlock();
466
467    POOLMEM *changer_cmd = get_pool_memory(PM_FNAME);
468    POOL_MEM results(PM_MESSAGE);
469    lock_changer(dcr);
470    Jmsg(jcr, M_INFO, 0,
471         _("3307 Issuing autochanger \"unload slot %d, drive %d\" command.\n"),
472         dev->get_slot(), dev->drive_index);
473
474    Dmsg2(100, "Issuing autochanger \"unload slot %d, drive %d\" command.\n",
475         dev->get_slot(), dev->drive_index);
476
477    changer_cmd = edit_device_codes(dcr, changer_cmd, 
478                 dcr->device->changer_command, "unload");
479    dev->close();
480    Dmsg2(200, "close dev=%s reserve=%d\n", dev->print_name(), 
481       dev->num_reserved());
482    Dmsg1(100, "Run program=%s\n", changer_cmd);
483    int stat = run_program_full_output(changer_cmd, timeout, results.addr());
484    dcr->VolCatInfo.Slot = save_slot;
485    dcr->dev = save_dev;
486    if (stat != 0) {
487       berrno be;
488       be.set_errno(stat);
489       Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
490               dev->get_slot(), dev->drive_index, be.bstrerror());
491
492       Dmsg3(100, "Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n",
493               dev->get_slot(), dev->drive_index, be.bstrerror());
494       ok = false;
495       dev->clear_slot();          /* unknown */
496    } else {
497       Dmsg2(100, "Slot %d unloaded %s\n", dev->get_slot(), dev->print_name());
498       dev->set_slot(0);           /* nothing loaded */
499    }
500    dev->clear_unload();
501    unlock_changer(dcr);
502
503    dev->dunlock();
504
505    free_volume(dev);               /* Free any volume associated with this drive */
506    free_pool_memory(changer_cmd);
507    return ok;
508 }
509
510
511
512 /*
513  * List the Volumes that are in the autoloader possibly
514  *   with their barcodes.
515  *   We assume that it is always the Console that is calling us.
516  */
517 bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)  
518 {
519    DEVICE *dev = dcr->dev;
520    uint32_t timeout = dcr->device->max_changer_wait;
521    POOLMEM *changer;
522    BPIPE *bpipe;
523    int len = sizeof_pool_memory(dir->msg) - 1;
524    bool ok = false;
525    int stat;
526
527    if (!dev->is_autochanger() || !dcr->device->changer_name ||
528        !dcr->device->changer_command) {
529       if (strcmp(cmd, "drives") == 0) {
530          dir->fsend("drives=1\n");
531       }
532       dir->fsend(_("3993 Device %s not an autochanger device.\n"),
533          dev->print_name());
534       return false;
535    }
536
537    if (strcmp(cmd, "drives") == 0) {
538       AUTOCHANGER *changer_res = dcr->device->changer_res;
539       int drives = 1;
540       if (changer_res) {
541          drives = changer_res->device->size();
542       }
543       dir->fsend("drives=%d\n", drives);
544       Dmsg1(100, "drives=%d\n", drives);
545       return true;
546    }
547
548    changer = get_pool_memory(PM_FNAME);
549    lock_changer(dcr);
550    /* Now issue the command */
551    changer = edit_device_codes(dcr, changer, 
552                  dcr->device->changer_command, cmd);
553    dir->fsend(_("3306 Issuing autochanger \"%s\" command.\n"), cmd);
554    bpipe = open_bpipe(changer, timeout, "r");
555    if (!bpipe) {
556       dir->fsend(_("3996 Open bpipe failed.\n"));
557       goto bail_out;
558    }
559    if (strcmp(cmd, "list") == 0) {
560       /* Get output from changer */
561       while (fgets(dir->msg, len, bpipe->rfd)) {
562          dir->msglen = strlen(dir->msg);
563          Dmsg1(100, "<stored: %s\n", dir->msg);
564          bnet_send(dir);
565       }
566    } else if (strcmp(cmd, "slots") == 0 ) {
567       char buf[100], *p;
568       /* For slots command, read a single line */
569       buf[0] = 0;
570       fgets(buf, sizeof(buf)-1, bpipe->rfd);
571       buf[sizeof(buf)-1] = 0;
572       /* Strip any leading space in front of # of slots */
573       for (p=buf; B_ISSPACE(*p); p++)
574         { }
575       dir->fsend("slots=%s", p);
576       Dmsg1(100, "<stored: %s", dir->msg);
577    } 
578                  
579    stat = close_bpipe(bpipe);
580    if (stat != 0) {
581       berrno be;
582       be.set_errno(stat);
583       dir->fsend(_("Autochanger error: ERR=%s\n"), be.bstrerror());
584    }
585    bnet_sig(dir, BNET_EOD);
586    ok = true;
587
588 bail_out:
589    unlock_changer(dcr);
590    free_pool_memory(changer);
591    return true;
592 }
593
594
595 /*
596  * Edit codes into ChangerCommand
597  *  %% = %
598  *  %a = archive device name
599  *  %c = changer device name
600  *  %d = changer drive index
601  *  %f = Client's name
602  *  %j = Job name
603  *  %o = command
604  *  %s = Slot base 0
605  *  %S = Slot base 1
606  *  %v = Volume name
607  *
608  *
609  *  omsg = edited output message
610  *  imsg = input string containing edit codes (%x)
611  *  cmd = command string (load, unload, ...)
612  *
613  */
614 char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd)
615 {
616    const char *p;
617    const char *str;
618    char add[20];
619
620    *omsg = 0;
621    Dmsg1(1800, "edit_device_codes: %s\n", imsg);
622    for (p=imsg; *p; p++) {
623       if (*p == '%') {
624          switch (*++p) {
625          case '%':
626             str = "%";
627             break;
628          case 'a':
629             str = dcr->dev->archive_name();
630             break;
631          case 'c':
632             str = NPRT(dcr->device->changer_name);
633             break;
634          case 'd':
635             sprintf(add, "%d", dcr->dev->drive_index);
636             str = add;
637             break;
638          case 'o':
639             str = NPRT(cmd);
640             break;
641          case 's':
642             sprintf(add, "%d", dcr->VolCatInfo.Slot - 1);
643             str = add;
644             break;
645          case 'S':
646             sprintf(add, "%d", dcr->VolCatInfo.Slot);
647             str = add;
648             break;
649          case 'j':                    /* Job name */
650             str = dcr->jcr->Job;
651             break;
652          case 'v':
653             str = NPRT(dcr->VolumeName);
654             break;
655          case 'f':
656             str = NPRT(dcr->jcr->client_name);
657             break;
658
659          default:
660             add[0] = '%';
661             add[1] = *p;
662             add[2] = 0;
663             str = add;
664             break;
665          }
666       } else {
667          add[0] = *p;
668          add[1] = 0;
669          str = add;
670       }
671       Dmsg1(1900, "add_str %s\n", str);
672       pm_strcat(&omsg, (char *)str);
673       Dmsg1(1800, "omsg=%s\n", omsg);
674    }
675    Dmsg1(800, "omsg=%s\n", omsg);
676    return omsg;
677 }