Article 159217 of comp.os.vms:
Jon Barker wrote:
> 
> While we're on the subject of $BRKTHRU..
> 
> Can anyone post/mail me an example of it's use preferably C?
> 
> Be very grateful, can't seem to get it to do anything here, which might be
> due to some kind of privilege?
> 
> Jon Barker

Here is a small function to send a message to a single user or all
users. And yes, you do need OPER privilege to make it work.

-Blake Yeager

/*****************************************************************

Name:
        utl_brdcst

Description:
        Broadcasts a message to a user or optionally all users. 

Calling sequence:

        int                             stat;
        struct dsc$descriptor_s         *msg;
        struct dsc$descriptor_s         *user;

        stat = utl_brdcst(msg, user)

Inputs:

        msg:    Address of string descriptor pointing to broadcast
		message text. Required.
        user:   Address of string descriptor pointing to username.
 		Optional. If omitted broadcast to all users/

Outputs:

        None.

Function return value:

        Return status from sys$brkthru.

Limitations / Notes:

Modification History:

        Date            Who             Change
        Aug 30 1993     B. Yeager       Initial Release.

****************************************************************/

#include brkdef
#include descrip
#include varargs

#define TIMEOUT  20      /* number of seconds to wait for terminal */
typedef int iosb[4];

int sys$brkthru();
int lib$get_ef();
int lib$free_ef();
int lib$signal();

static brdcst_ast();
static iosb sb;

unsigned int utl_brdcst( va_alist )

va_dcl
{
    struct dsc$descriptor_s     *msg;
    struct dsc$descriptor_s     *user; 
    int                         stat;
    int                         rstat;
    int                         narg;
    int                         efn;
    int                         i;
    unsigned long               astprm;
    unsigned long               to = TIMEOUT;
    va_list                     ap;

    va_count(narg);             /* get argument count */
    narg &= 0xff;               /* fix it up */
    if (narg < 1 || narg > 2)
        return SS$_BADPARAM;
    
    stat = lib$get_ef(&efn);
    if (!(stat & 1))
        efn = 0;

    va_start(ap);
    msg = va_arg(ap, struct dsc$descriptor_s *);
    if (narg > 1)
        user = va_arg(ap, struct dsc$descriptor_s *);
    va_end(ap);

    if (narg > 1)
        rstat = sys$brkthru(efn, msg, user, BRK$C_USERNAME, &sb, 0, 0,
0, 			to, brdcst_ast, astprm);
    else
        rstat = sys$brkthru(efn, msg, 0, BRK$C_ALLUSERS, &sb, 0, 0,
0, 				to, brdcst_ast, astprm);

    stat = lib$free_ef(&efn);

    return rstat;
}

brdcst_ast(astprm)
    int             astprm;
{
    int             stat;     

    if (!(sb[0] & 1))
        stat = lib$signal(sb[0]);

}


