batch_daemon.in 18.1 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
6 7 8
# All rights reserved.
#

9 10
use English;
use Getopt::Std;
11 12
use Fcntl;
use IO::Handle;
13 14 15 16 17 18

#
# Create a batch experiment.
#
# usage: batch_daemon
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
19 20
# TODO: Use "logger" instead of writing a log file.
#
21 22
sub usage()
{
23 24
    print STDOUT "Usage: batch_daemon [-d]\n" .
	"Use the -d option to prevent daemonization\n";
25 26
    exit(-1);
}
27
my  $optlist = "d";
28 29 30 31 32 33 34

#
# Configure variables
#
my $TB       = "@prefix@";
my $DBNAME   = "@TBDBNAME@";
my $TBOPS    = "@TBOPSEMAIL@";
35
my $TBLOGS   = "@TBLOGSEMAIL@";
36

37 38 39 40 41 42 43 44
#
# Only root can run this script.
#
if ($UID) {
    die("*** $0:\n".
	"    Only root can run this script!\n");
}

45 46 47 48 49 50 51
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

52 53 54
# Be careful not to exit on transient error
$libdb::DBQUERY_MAXTRIES = 10;

55
my $tbbindir = "$TB/bin/";
56
my $swapexp  = "$TB/bin/swapexp";
57
my $endexp   = "$TB/bin/endexp";
58
my $savelogs = "$TB/bin/savelogs";
59
my $avail    = "$TB/sbin/avail";
60 61
my $batchlog = "$TB/log/batchlog";
my $projroot = "/proj";
62
my $debug    = 0;
63

64 65 66 67
my $BSTATE_POSTED	= BATCHSTATE_POSTED;
my $BSTATE_ACTIVATING	= BATCHSTATE_ACTIVATING;
my $BSTATE_RUNNING	= BATCHSTATE_RUNNING;
my $BSTATE_TERMINATING	= BATCHSTATE_TERMINATING;
68
my $BSTATE_PAUSED	= BATCHSTATE_PAUSED;
69

70 71 72 73 74 75
#
# These are valid in the children, not the parent. I suppose I could use
# dynamically scoped variables, but hardly worth it.
#
my $eid;
my $pid;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
76
my $gid;
77
my $logname;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
78
my $nsfile;
79 80
my $userdir;
my $workdir;
81
my $user_name  = "Testbed Operations";
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
my $user_email = "$TBOPS";

#
# Turn off line buffering on output
#
$| = 1;

#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (@ARGV != 0) {
    usage();
}
106 107 108
if (defined($options{"d"})) {
    $debug = $options{"d"};
}
109 110

# Go to ground.
111
if (! $debug) {
112 113 114
    if (TBBackGround($batchlog)) {
	exit(0);
    }
115
}
116 117 118 119 120

#
# Loop, looking for batch experiments that want to run.
# 
while (1) {
121
    my($count, $i, $query_result, $pending_result, $running_result);
122
    my(%pending_row);
123 124 125 126 127
    my $retry_wait = TBGetSiteVar("batch/retry_wait");

    # Do not allow zero!
    $retry_wait = 60
	if ($retry_wait == 0);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
128

129
    #
130
    # Need to lock the table here because of cancelation in endexp.
131 132 133 134 135 136
    # See the comments in there. We need to atomically grab the next
    # batch experiment we want to try, and then change its state from
    # new to configuring. We want to grab just one experiment, since
    # it takes a while to configure an experiment, and grabbing a bunch and
    # locking them up might result in having to wait a really long time
    # to cancel a batch experiment that hasn't really tried to start yet!
137
    # Thats would ne annoying to users.
138
    #
139
    # So, now you're wondering what my selection criteria is? Well, its
140 141
    # damn simplistic. I set the "started" datetime field each attempt,
    # and I pick the batch_experiment with the oldest time, thereby cycling
142 143 144 145
    # through in a "least recently attempted" manner. In addition, we want
    # to throttle the number simultaneous batches that one person can
    # can have running at a time (curently to just one batch), so check to
    # to see if the person has another batch active (thats e2 below).
146 147
    #
    $query_result =
148 149
	DBQuery("lock tables experiments write, experiments as e1 write, ".
		"experiments as e2 write");
150 151
    if (! $query_result) {
	print "DB Error locking tables. Waiting a bit ...\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
152
	goto pause;
153 154 155
    }
    
    $pending_result =
156 157 158 159 160 161 162
	DBQueryWarn("SELECT e1.* FROM experiments as e1 ".
		    "left join experiments as e2 on ".
		    " e2.expt_head_uid=e1.expt_head_uid and ".
		    " e2.batchmode=1 and e2.batchstate='$BSTATE_RUNNING' and ".
		    " e1.pid=e2.pid and e1.eid!=e2.eid ".
		    "WHERE e2.eid is null and ".
		    " e1.batchmode=1 and e1.canceled=0 and ".
163
		    " e1.expt_locked is null and ".
164 165 166
		    " e1.batchstate='$BSTATE_POSTED' and ".
		    "  (e1.attempts=0 or ".
		    "    ((UNIX_TIMESTAMP() - ".
167
		    "      UNIX_TIMESTAMP(e1.expt_start) > ($retry_wait)))) ".
168
		    "ORDER BY e1.expt_start LIMIT 1");
169

170
    $running_result =
171 172
	DBQuery("select * from experiments ".
		"where batchmode=1 and batchstate='$BSTATE_RUNNING' ".
173
		"ORDER BY expt_start LIMIT 1");
174 175 176

    if (!$pending_result || !$running_result) {
	print "DB Error getting batch info. Waiting a bit ...\n";
177
	DBQuery("unlock tables");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
178
	goto pause;
179 180 181
    }

    if (!$pending_result->numrows && !$running_result->numrows) {
182
	DBQuery("unlock tables");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
183
	goto pause;
184 185 186
    }

    #
187
    # If we have a pending experiment to run, set its state to configuring
188
    # right away, while we have the tables locked. This prevents endexp
189
    # from seeing it as something it can cancel.
190
    #
191 192 193 194 195 196 197 198
    if ($pending_result->numrows) {
	%pending_row = $pending_result->fetchhash();

	# Local vars!
	my $eid = $pending_row{'eid'};
	my $pid = $pending_row{'pid'};

	$query_result = 
199 200 201
	    DBQuery("update experiments set expt_start=now(), ".
		    "batchstate='$BSTATE_ACTIVATING' ".
		    "where eid='$eid' and pid='$pid'");
202 203 204

	if (! $query_result) {
	    print "DB error setting batch $pid/$eid to configuring.\n";
205
	    DBQuery("unlock tables");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
206
	    goto pause;
207 208
	}
    }
209

210 211 212 213 214 215 216 217 218 219 220
    #
    # Okay, first we check the status of running batch mode experiments
    # since we want to end those before trying to start any new ones, cause
    # it would be nice to have as many nodes available as possible before
    # trying to add a new one. This can potentially delay startup, but thats
    # okay. Its a batch system.
    #
    # If you are wondering why I check for finished experiments in the main
    # loop instead of in the child that started the experiment, its so that
    # we fire up again and look for them in the event that paper goes down.
    #
221 222 223 224
    if ($running_result->numrows) {
	my %running_row = $running_result->fetchhash();
	my $canceled    = $running_row{'canceled'};
	
225
	if ($canceled) {
226 227 228 229 230 231 232 233 234 235 236
	    # Local vars!
	    my $eid = $running_row{'eid'};
	    my $pid = $running_row{'pid'};

	    #
	    # Have to set the state to busy so that no one will be able
	    # to mess with the experiment while we deal with termination.
	    # 
	    TBSetBatchState($pid, $eid, BATCHSTATE_RUNNING_LOCKED());
	    DBQueryWarn("unlock tables");
	    
237 238
	    # Look at the cancel flag.
	    if ($canceled == BATCHMODE_CANCELTERM) {
239
		dosomething("cancel", %running_row);
240 241
	    }
	    elsif ($canceled == BATCHMODE_CANCELSWAP) {
242 243 244 245
		dosomething("swap", %running_row);
	    }
	    else {
		print "Improper cancel flag: $canceled\n";
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
	else {
	    #
	    # Have to set the state to busy so that no one will be able
	    # to mess with the experiment while trying to determine if
	    # the batch is done.
	    # 
	    TBSetBatchState($pid, $eid, BATCHSTATE_RUNNING_LOCKED());
	    DBQueryWarn("unlock tables");

	    if (isexpdone(%running_row)) {
		#
		# Terminate the experiment. Set the state appropriately
		# so that swapexp will accept it. It is okay to do this
		# with the table unlocked since no one is allowed to mess
		# with a batch experiment in the RUNNING_LOCKED state. 
		# 
		dosomething("swap", %running_row);
	    }
	    else {
		#
		# Reset the state to RUNNING. It is okay to do this with
		# the table unlocked since no one is allowed to mess
		# with a batch experiment in the RUNNING_LOCKED state.
		# 
		TBSetBatchState($pid, $eid, $BSTATE_RUNNING);
	    }
274 275
	}
    }
276 277 278 279
    else {
	# no one above unlocked the tables ...
	DBQueryWarn("unlock tables");
    }
280 281 282 283 284 285 286

    #
    # Finally start an actual experiment!
    #
    if ($pending_result->numrows) {
	dosomething("start", %pending_row);
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
287
  pause:
288
    sleep(15);
289 290 291
}

#
292
# Do something as the user. Either, start, end, or cancel an experiment.
293
#
294
sub dosomething($$)
295
{
296 297
    my($dowhat)   = shift;
    my(%exphash)  = @_;
298
    my($unix_uid, $unix_gid, $unix_gname, $row, $query_result);
299 300

    # Global vars
301 302 303
    $eid     = $exphash{'eid'};
    $pid     = $exphash{'pid'};
    $gid     = $exphash{'gid'};
304 305
    $userdir = $exphash{'path'};
    $workdir = TBExptWorkDir($pid, $eid);
306 307 308 309
    $nsfile  = "$eid.ns";
    
    # Locals
    my $creator = $exphash{'expt_head_uid'};
310

311 312 313 314 315 316 317
    print "Doing a '$dowhat' to batch experiment $pid/$eid\n";

    #
    # Create a temporary name for a log file. We do this in the parent so
    # we can remove it when the child ends. The child could remove it, but
    # since it is open in the child, it has the tendency to stick around.
    #
318
    $logname = TBExptCreateLogFile($pid, $eid, "${dowhat}-batch");
319

320 321 322
    #
    # Start up a child to run the guts. The parent waits. If the
    # experiment configures okay, the parent can return to try something
323
    # else.
324 325 326
    #
    $childpid = fork();
    if ($childpid) {
327

328
	print TBDateTimeFSSafe() . "\n";
329 330
	print "Child PID $childpid started to $dowhat $pid/$eid\n";

331
	waitpid($childpid, 0);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
332
	my $status = $? >> 8;
333

334
	print TBDateTimeFSSafe() . "\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
335
	print "Child PID $childpid exited with exit status $status\n";
336

337
        #
338
        # Close the log file.
339 340
	# The exp dir might be gone if the batch was killed/canceled.
        #
341
	if (-e $userdir) {
342 343
	    TBExptCloseLogFile($pid, $eid);
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
344
	return $status;
345
    }
346
    openlog($logname);
347 348
    TBExptSetLogFile($pid, $eid, $logname);
    TBExptOpenLogFile($pid, $eid);
349

350 351 352
    #
    # Get some user information. 
    #
353
    if (!UserDBInfo($creator, \$user_name, \$user_email)) {
354
	fatal("DB Error getting user information for uid $creator");
355
    }
356
    
357 358
    chdir("$workdir") or
	fatal("Could not cd into $workdir!");
359 360 361 362 363

    #
    # Figure out the unix uid/gid that the experiment configuration is
    # going to run as. 
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
364
    (undef,undef,$unix_uid) = getpwnam($creator) or
365
	fatal("No such user $creator");
366 367
    TBGroupUnixInfo($pid, $gid, \$unix_gid, \$unix_gname) or
	fatal("No such group $pid/$gid");
368

369 370 371
    #
    # Change the ownership of the log file before we flip.
    #
372 373
    chown($unix_uid, $unix_gid, $logname) or
	fatal("Could not chown $logname to $unix_uid/$unix_gid!");
374 375

    # Flip to the user. We never flip back.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
376 377
    $EGID = $GID = $unix_gid;
    $EUID = $UID = $unix_uid;
378
    $ENV{'USER'} = $creator;
379
    
380 381 382
    if ($dowhat eq "start") {
	startexp(%exphash);
    }
383 384
    elsif ($dowhat eq "swap") {
	swapexp(%exphash);
385 386
    }
    elsif ($dowhat eq "cancel") {
387
	cancelexp(%exphash);
388 389 390 391 392 393 394 395 396 397
    }
    exit(0);
}

#
# Try to start an experiment. Never returns.
# 
sub startexp($)
{
    my(%exphash)  = @_;
398
    my($exit_status, $running, $query_result);
399 400 401

    my $attempts  = $exphash{'attempts'};

402
    #
403
    # Try to swap the experiment in. 
404
    #
405
    system("$swapexp -b -s in $pid $eid");
406 407
    $exit_status = $? >> 8;
    $running     = 1;
408 409 410 411 412
    if ($exit_status) {
	$running = 0;
    }
    
    #
413 414
    # Look for cancelation. If we get a DB error on this, just continue cause
    # we can pick up the cancelation later.
415 416
    #
    $query_result =
417
	DBQueryWarn("select canceled from experiments ".
418
		    "where eid='$eid' and pid='$pid'");
419

420
    if ($query_result) {
421 422
	my ($canceled) = $query_result->fetchrow_array();
	$exphash{'canceled'} = $canceled;
423

424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
	# Yuck: This is strictly for the benefit of swapexp() below.
	$exphash{'batchstate'} = BATCHSTATE_RUNNING
	    if ($running);
	
	if ($canceled) {
	    # Look at the cancel flag.
	    if ($canceled == BATCHMODE_CANCELTERM) {
		cancelexp(%exphash);
	    }
	    elsif ($canceled == BATCHMODE_CANCELSWAP) {
		swapexp(%exphash);
	    }
	    else {
		print "Improper cancel flag: $canceled\n";
	    }
439 440 441
	    #
	    # Never returns, but just to be safe ...
	    #
442
	    exit(-1);
443 444
	}
    }
445 446 447 448

    #
    # If the configuration failed for lack of nodes, then don't send
    # email unless the number of attempts starts to get big.
449
    #
450 451 452
    # If the configuration failed for some other reason, then send email.
    # We have to reset the state to "new" so that it will be retried again
    # later. 
453 454
    #
    if (! $running) {
455 456 457 458
	#
	# XXX - What if this update fails?
	# 
	$query_result = 
459
	    DBQueryWarn("update experiments set attempts=attempts+1 ".
460
			"where eid='$eid' and pid='$pid'");
461

462
	#
463 464 465 466
	# The exit value is important. If its -1 or 1, thats bad. Anything
	# else implies an assign violation that is (hopefully) transient.
	# We leave it up the user to kill the batch if it looks like its
	# never going to work.
467 468
	#
	if ($exit_status == 1 || $exit_status == -1) {
469 470 471
	    TBSetBatchState($pid, $eid, $BSTATE_PAUSED);
	    TBUnLockExp($pid, $eid);
	    
472
	    email_status("Experiment startup has failed with a fatal error!\n".
473 474
			 "Batch has been dequeued so that you may check it.");

475
	    exit($exit_status);
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
	
	if (($attempts % 30) == 0) {
	    $attempts++;

	    my $msg =
		"Could not configure Batch Mode experiment $pid/$eid.\n".
		"\n".
		"There was an assignment violation (please check the log)\n".
		"that prevented it from being scheduled. The violation\n".
		"might result from not enough nodes or not enough link\n".
		"bandwidth. If you feel that the violation is in error,\n".
		"please cancel the batch and notify $TBOPS\n".
		"Otherwise, another attempt will be made in a little while.\n".
		"\n". 
		"There have been $attempts attempts to start this batch.";

	    email_status($msg);
	}

	#
	# There is some state that needs to be reset so that another
	# attempt can be made.
	# 
	TBSetBatchState($pid, $eid, $BSTATE_POSTED);
501
	TBUnLockExp($pid, $eid);
502
	    
503
	exit($exit_status);
504 505 506 507 508
    }

    #
    # Well, it configured! Lets set it state to running.
    #
509
    TBSetBatchState($pid, $eid, $BSTATE_RUNNING);
510
    TBUnLockExp($pid, $eid);
511
    
512
    email_status("Batch Mode experiment $pid/$eid is now running!\n".
513
		 "Please consult the Web interface to see how it is doing.");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
514

515
    #
516
    # Done with this phase. Must exit.
517
    #
518 519
    exit(0);
}
520

521
#
522
# A batch has completed. Swap it out. 
523
#
524
sub swapexp($;$)
525 526
{
    my(%exphash)  = @_;
527
    my $canceled  = $exphash{'canceled'};
528
    my $running   = ($exphash{'batchstate'} eq BATCHSTATE_RUNNING);
529

530
    if ($running) {
531
	#
532 533
	# Have to set the state to terminating so that swap/end exp
	# will accept it.
534
	# 
535 536 537 538 539 540 541 542 543
	TBSetBatchState($pid, $eid, $BSTATE_TERMINATING);
	
	system("$swapexp -b -s out $pid $eid");
	if ($?) {
	    #
	    # TB admin is going to have to clean up. 
	    # 
	    fatal("Swapping out Batch Mode experiment $pid/$eid");
	}
544 545 546 547 548
    }
    #
    # Set the state to paused to ensure that it is not run again until
    # the user wants to.
    # 
549
    TBSetBatchCancelFlag($pid, $eid, BATCHMODE_CANCELCLEAR);
550
    TBSetBatchState($pid, $eid, $BSTATE_PAUSED);
551
    TBUnLockExp($pid, $eid);
552
    
553 554 555 556 557
    if ($canceled) {
	email_status("Batch Mode experiment $pid/$eid has been stopped!");
    }
    else {
	email_status("Batch Mode experiment $pid/$eid has finished!");
558
    }
559
   
560
    #
561
    # Child must exit!
562
    #
563 564 565 566 567 568
    exit(0);
}

#
# Cancel an experiment. Never returns.
#
569
sub cancelexp($)
570 571 572
{
    my(%exphash) = @_;
    
573 574 575
    #
    # Have to set the state to terminating so that swap/end exp will accept it.
    # 
576
    TBSetBatchState($pid, $eid, $BSTATE_TERMINATING);
577 578 579 580 581

    #
    # It does not matter if the experiment is running; endexp does the
    # right thing.
    # 
582 583 584 585 586 587
    system("$endexp -b $pid $eid");
    if ($?) {
	#
	# TB admin is going to have to clean up. 
	# 
	fatal("Terminating Batch Mode experiment $pid/$eid");
588
    }
589
    donotify("Your Batch Mode experiment has been canceled!", "Canceled", 0);
590 591 592 593 594 595 596
   
    #
    # Child must exit!
    #
    exit(0);
}

597 598 599 600 601 602 603
#
# Check experiment status. Looks to see if all of the nodes in an
# experiment have reported in.
#
sub isexpdone($)
{
    my(%exphash)  = @_;
604
    my($query_result, @row);
605 606 607 608 609
    
    # Global vars
    $eid = $exphash{'eid'};
    $pid = $exphash{'pid'};

610
    print TBDateTimeFSSafe() . "\n";
611 612 613 614 615 616
    print "Checking to see if $pid/$eid has finished up yet\n";

    #
    # Look to see if any nodes yet to report status. If so, spin again.
    #
    $query_result =
617 618 619
	DBQueryWarn("SELECT startstatus,bootstatus FROM nodes ".
		    "LEFT JOIN reserved ON nodes.node_id=reserved.node_id ".
		    "WHERE reserved.eid='$eid' and reserved.pid='$pid'");
620 621 622 623 624

    if (! $query_result) {
	return 0;
    }

625 626 627 628 629 630 631 632 633 634 635 636 637
    #
    # Well, right now a node is considered finished up only if its
    # boot did not fail, and it has reported start command status.
    # The idea being that if the boot failed, then its status will
    # never be reported anyway, and we might as well consider the node
    # done (else the experiment would never end).
    # 
    while (@row = $query_result->fetchrow_array()) {
	if ($row[1] eq NODEBOOTSTATUS_FAILED) {
	    next;
	}
	if ($row[0] eq NODESTARTSTATUS_NOSTATUS) {
	    return 0;
638 639
	}
    }
640
    return 1;
641 642 643 644
}

#
# Start up a child, and set its descriptors talking to a log file.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
645
# The log file already exists, created with mktemp above.
646 647 648 649 650 651 652
# 
sub openlog($)
{
    my($logname) = $_[0];
	
    #
    # We have to disconnect from the caller by redirecting both STDIN and
Leigh B. Stoller's avatar
Leigh B. Stoller committed
653 654
    # STDOUT away from the pipe. Otherwise the caller will continue to wait
    # even though the parent has exited. 
655 656
    #
    open(STDIN, "< /dev/null") or
657
	fatal("opening /dev/null for STDIN: $!");
658 659 660 661 662 663

    open(STDERR, ">> $logname") or
	fatal("opening $logname for STDERR: $!");
    open(STDOUT, ">> $logname") or
	fatal("opening $logname for STDOUT: $!");

664 665 666
    STDOUT->autoflush(1);
    STDERR->autoflush(1);

667 668 669
    return 0;
}

670 671 672 673 674
#
# A fatal error is something that the user does not need to know about.
# Caused by a breakdown in the TB system. Generally speaking, once the
# experiment is running, this should not be used.
# 
675
sub fatal($)
676 677 678
{
    my($mesg) = $_[0];

679
    donotify($mesg, "Failure", 1);
680 681 682 683

    exit(-1);
}

684 685 686
#
# Something the user cares about. 
# 
687
sub email_status($)
688
{
689
    my($mesg) = $_[0];
690

691
    donotify($mesg, "Status", 0);
692 693
}

694
sub donotify($$$)
695
{
696
    my($mesg, $subtext, $iserr) = @_;
697
    my($subject, $from, $to, $hdrs);
698
    my $MAIL;
699

700 701 702
    $mesg = "$mesg\n";

    print STDOUT "$mesg";
703

704
    $subject = "Batch Mode Experiment $subtext $pid/$eid";
705
    $from    = $TBOPS;
706 707 708 709 710 711
    $hdrs    = "Reply-To: $TBOPS";
    
    #
    # An error goes just to Testbed Operations. Normal status messages go
    # to the user and to the Testbed Logs address.
    # 
712
    if ($iserr) {
713
	$to = "$TBOPS";
714 715
    }
    else {
716 717 718
	$to   = "$user_name <$user_email>";
	$hdrs = "Bcc: $TBLOGS\n".
	        "$hdrs";
719 720
    }

721
    SENDMAIL($to, $subject, $mesg, $from, $hdrs,
722
	     ($logname, "assign.log", $nsfile));
723
}