From: Simon Wilkinson Date: Sat, 7 Nov 2009 21:21:00 +0000 (+0000) Subject: Add printf format checks to util's log functions X-Git-Tag: openafs-devel-1_5_72~58 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=68463b6ab9c664303692ac264871723c27bfc524;p=packages%2Fo%2Fopenafs.git Add printf format checks to util's log functions Add gcc printf format checks to all of the logging functions defined in src/util/afsutil.h Deal with the fallout, in particular create cast functions to go from VolumeId and VnodeId to (unsigned int) Change-Id: I28181b73cfeac22cf869d34e75a8335e65125e36 Reviewed-on: http://gerrit.openafs.org/793 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/util/afsutil.h b/src/util/afsutil.h index 5b73ad4bc..3aa037bce 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -40,10 +40,14 @@ extern int serverLogSyslog; extern int serverLogSyslogFacility; extern char *serverLogSyslogTag; #endif -extern void vFSLog(const char *format, va_list args); +extern void vFSLog(const char *format, va_list args) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 0); + extern void SetLogThreadNumProgram(int (*func) (void) ); -/*@printflike@*/ extern void FSLog(const char *format, ...); +extern void FSLog(const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2); + #define ViceLog(level, str) do { if ((level) <= LogLevel) (FSLog str); } while (0) #define vViceLog(level, str) do { if ((level) <= LogLevel) (vFSLog str); } while (0) @@ -54,26 +58,31 @@ extern void SetupLogSignals(void); extern int afs_vsnprintf( /*@out@ */ char *p, size_t avail, const char *fmt, va_list ap) + AFS_ATTRIBUTE_FORMAT(__printf__, 3, 0) /*@requires maxSet(p) >= (avail-1)@ */ /*@modifies p@ */ ; extern /*@printflike@ */ int -afs_snprintf( /*@out@ */ char *p, size_t avail, - const char *fmt, ...) +afs_snprintf( /*@out@ */ char *p, size_t avail, const char *fmt, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 3, 4) /*@requires maxSet(p) >= (avail-1)@ */ /*@modifies p@ */ ; extern int -afs_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args); +afs_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) + AFS_ATTRIBUTE_FORMAT(__printf__, 3, 0); extern int -afs_vasprintf (char **ret, const char *format, va_list args); +afs_vasprintf (char **ret, const char *format, va_list args) + AFS_ATTRIBUTE_FORMAT(__printf__, 2, 0); extern int -afs_asprintf (char **ret, const char *format, ...); +afs_asprintf (char **ret, const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 2, 3); extern int -afs_asnprintf (char **ret, size_t max_sz, const char *format, ...); +afs_asnprintf (char **ret, size_t max_sz, const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 3, 4); /* special version of ctime that clobbers a *different static variable, so * that ViceLog can call ctime and not cause buffer confusion. diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index fc245777f..00cd17b05 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -434,8 +434,8 @@ CallPostamble(register struct rx_connection *aconn, afs_int32 ret, if (ahost != thost) { /* host/client recycle */ char hoststr[16], hoststr2[16]; - ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost " - "%s:%d (%x)\n", + ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost " + "%s:%d (%p)\n", afs_inet_ntoa_r(ahost->host, hoststr), ntohs(ahost->port), ahost, @@ -447,7 +447,7 @@ CallPostamble(register struct rx_connection *aconn, afs_int32 ret, h_Release_r(ahost); } else { char hoststr[16]; - ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n", + ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n", afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), thost)); @@ -7288,8 +7288,11 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, if (Pos == 0) CopyOnWrite_off0++; if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len; - ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %lu.%lu (%s) off 0x%llx size 0x%llx\n", - V_id(volptr), targetptr->vnodeNumber, V_name(volptr), 0, Pos)); + ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) " + "off 0x0 size 0x%llx\n", + afs_printable_VolumeId_u(V_id(volptr)), + afs_printable_VnodeId_u(targetptr->vnodeNumber), + V_name(volptr), Pos)); if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) { ViceLog(25, ("StoreData : CopyOnWrite failed\n")); volptr->partition->flags &= ~PART_DONTUPDATE; @@ -7443,8 +7446,11 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, if (origfdP) { /* finish CopyOnWrite */ if ( (CoW_off = Pos + Length) < NewLength) { errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off); - ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %lu.%lu (%s) off 0x%llx size 0x%llx returns %d\n", - V_id(volptr), targetptr->vnodeNumber, V_name(volptr), CoW_off, CoW_len, errorCode)); + ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) " + "off 0x%llx size 0x%llx returns %d\n", + afs_printable_VolumeId_u(V_id(volptr)), + afs_printable_VnodeId_u(targetptr->vnodeNumber), + V_name(volptr), CoW_off, CoW_len, errorCode)); } FDH_CLOSE(origfdP); } diff --git a/src/viced/callback.c b/src/viced/callback.c index 9ff0fb122..cbe90d770 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -731,7 +731,7 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, if (!hp || !idx) { ViceLog(0, - ("BCB: INTERNAL ERROR: hp=%x, cba=%x, thead=%u\n", + ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n", hp, cba, idx)); } else { /* @@ -740,7 +740,8 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, if (MultiBreakCallBackAlternateAddress(hp, afidp)) { if (ShowProblems) { ViceLog(7, - ("BCB: Failed on file %u.%u.%u, Host %x (%s:%d) is down\n", + ("BCB: Failed on file %u.%u.%u, " + "Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->Unique, @@ -813,7 +814,7 @@ BreakCallBack(struct host *xhost, AFSFid * fid, int flag) char hoststr[16]; ViceLog(7, - ("BCB: BreakCallBack(Host %x all but %s:%d, (%u,%u,%u))\n", + ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n", xhost, afs_inet_ntoa_r(xhost->host, hoststr), ntohs(xhost->port), fid->Volume, fid->Vnode, fid->Unique)); @@ -843,7 +844,7 @@ BreakCallBack(struct host *xhost, AFSFid * fid, int flag) ViceLog(0, ("BCB: BOGUS! cb->hhead is NULL!\n")); } else if (thishost->hostFlags & VENUSDOWN) { ViceLog(7, - ("BCB: %x (%s:%d) is down; delaying break call back\n", + ("BCB: %p (%s:%d) is down; delaying break call back\n", thishost, afs_inet_ntoa_r(thishost->host, hoststr), ntohs(thishost->port))); cb->status = CB_DELAYED; @@ -906,7 +907,7 @@ DeleteCallBack(struct host *host, AFSFid * fid) pcb = FindCBPtr(fe, host); if (!*pcb) { ViceLog(8, - ("DCB: No call back for host %x (%s:%d), (%u, %u, %u)\n", + ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), fid->Volume, fid->Vnode, fid->Unique)); h_Unlock_r(host); @@ -1028,15 +1029,17 @@ BreakDelayedCallBacks_r(struct host *host) if (code) { if (ShowProblems) { ViceLog(0, - ("CB: Call back connect back failed (in break delayed) for Host %x (%s:%d)\n", + ("CB: Call back connect back failed (in break delayed) " + "for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); } host->hostFlags |= VENUSDOWN; } else { ViceLog(25, - ("InitCallBackState success on %x (%s:%d)\n", - host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); + ("InitCallBackState success on %p (%s:%d)\n", + host, afs_inet_ntoa_r(host->host, hoststr), + ntohs(host->port))); /* reset was done successfully */ host->hostFlags |= RESETDONE; host->hostFlags &= ~VENUSDOWN; @@ -1075,14 +1078,16 @@ BreakDelayedCallBacks_r(struct host *host) int i; if (ShowProblems) { ViceLog(0, - ("CB: XCallBackBulk failed, Host %x (%s:%d); callback list follows:\n", + ("CB: XCallBackBulk failed, Host %p (%s:%d); " + "callback list follows:\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); } for (i = 0; i < nfids; i++) { if (ShowProblems) { ViceLog(0, - ("CB: Host %x (%s:%d), file %u.%u.%u (part of bulk callback)\n", + ("CB: Host %p (%s:%d), file %u.%u.%u " + "(part of bulk callback)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), fids[i].Volume, fids[i].Vnode, fids[i].Unique)); @@ -1128,7 +1133,7 @@ MultiBreakVolumeCallBack_r(struct host *host, int isheld, /* Do not care if the host is now HOSTDELETED */ if (ShowProblems) { ViceLog(0, - ("BVCB: volume callback for Host %x (%s:%d) failed\n", + ("BVCB: volume callback for Host %p (%s:%d) failed\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); } @@ -1388,7 +1393,7 @@ BreakLaterCallBacks(void) /* leave hold for MultiBreakVolumeCallBack to clear */ } else { ViceLog(125, - ("Found host %x (%s:%d) non-DELAYED cb for %u:%u:%u\n", + ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), fe->vnode, fe->unique, fe->volid)); } @@ -1616,7 +1621,7 @@ ClearHostCallbacks_r(struct host *hp, int locked) struct rx_connection *cb_conn = NULL; ViceLog(5, - ("GSS: Delete longest inactive host %x (%s:%d)\n", + ("GSS: Delete longest inactive host %p (%s:%d)\n", hp, afs_inet_ntoa_r(hp->host, hoststr), ntohs(hp->port))); h_Hold_r(hp); @@ -1977,12 +1982,15 @@ cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe) if ((fe->firstcb && !fe->ncbs) || (!fe->firstcb && fe->ncbs)) { - ViceLog(0, ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%d, fe->firstcb=%d, fe->ncbs=%d)\n", - fetoi(fe), fe->firstcb, fe->ncbs)); + ViceLog(0, ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n", + afs_printable_uint32_lu(fetoi(fe)), + afs_printable_uint32_lu(fe->firstcb), + afs_printable_uint32_lu(fe->ncbs))); ret = 1; } if (cb_stateVerifyFCBList(state, fe)) { - ViceLog(0, ("cb_stateVerifyFE: error: FCBList failed verification (fei=%d)\n", fetoi(fe))); + ViceLog(0, ("cb_stateVerifyFE: error: FCBList failed verification (fei=%lu)\n", + afs_printable_uint32_lu(fetoi(fe)))); ret = 1; } @@ -2986,7 +2994,7 @@ MultiBreakCallBackAlternateAddress_r(struct host *host, assert(j); /* at least one alternate address */ ViceLog(125, - ("Starting multibreakcall back on all addr for host %x (%s:%d)\n", + ("Starting multibreakcall back on all addr for host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); H_UNLOCK; multi_Rx(conns, j) { @@ -3081,7 +3089,7 @@ MultiProbeAlternateAddress_r(struct host *host) assert(j); /* at least one alternate address */ ViceLog(125, - ("Starting multiprobe on all addr for host %x (%s:%d)\n", + ("Starting multiprobe on all addr for host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); H_UNLOCK; diff --git a/src/viced/callback.h b/src/viced/callback.h index 2f4cca803..a74095f53 100644 --- a/src/viced/callback.h +++ b/src/viced/callback.h @@ -100,11 +100,11 @@ struct VCBParams { /* call back indices to pointers, and vice-versa */ #define itocb(i) ((i)?CB+(i):0) -#define cbtoi(cbp) (!(cbp)?0:(cbp)-CB) +#define cbtoi(cbp) ((afs_uint32)(!(cbp)?0:(cbp)-CB)) /* file entry indices to pointers, and vice-versa */ #define itofe(i) ((i)?FE+(i):0) -#define fetoi(fep) (!(fep)?0:(fep)-FE) +#define fetoi(fep) ((afs_uint32)(!(fep)?0:(fep)-FE)) /* Timeouts: there are 128 possible timeout values in effect at any * given time. Each timeout represents timeouts in an interval of 128 diff --git a/src/viced/host.c b/src/viced/host.c index 1aaeff45a..6395925f9 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -289,7 +289,8 @@ hpr_Initialize(struct ubik_client **uclient) code = afsconf_GetCellInfo(tdir, cellstr, "afsprot", &info); if (code) { - ViceLog(0, ("hpr_Initialize: Could not locate cell %s in %s/%s", cellstr, confDir, AFSDIR_CELLSERVDB_FILE)); + ViceLog(0, ("hpr_Initialize: Could not locate cell %s in %s/%s", + cellstr, confDir->name, AFSDIR_CELLSERVDB_FILE)); afsconf_Close(tdir); return code; } @@ -659,12 +660,12 @@ h_gethostcps_r(register struct host *host, register afs_int32 now) */ host->hcpsfailed = 1; ViceLog(0, - ("Warning: GetHostCPS failed (%d) for %x (%s:%d); will retry\n", + ("Warning: GetHostCPS failed (%d) for %p (%s:%d); will retry\n", code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); } else { host->hcpsfailed = 0; ViceLog(1, - ("gethost: GetHostCPS failed (%d) for %x (%s:%d); ignored\n", + ("gethost: GetHostCPS failed (%d) for %p (%s:%d); ignored\n", code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); } if (host->hcps.prlist_val) @@ -892,7 +893,8 @@ h_TossStuff_r(register struct host *host) if (code < 0) { char hoststr[16]; ViceLog(0, - ("Warning: h_TossStuff_r failed: Host %" AFS_PTR_FMT " (%s:%d) client %x was locked.\n", + ("Warning: h_TossStuff_r failed: Host %p (%s:%d) " + "client %p was locked.\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), client)); return; @@ -901,7 +903,8 @@ h_TossStuff_r(register struct host *host) if (client->refCount) { char hoststr[16]; ViceLog(0, - ("Warning: h_TossStuff_r failed: Host %" AFS_PTR_FMT " (%s:%d) client %x refcount %d.\n", + ("Warning: h_TossStuff_r failed: Host %p (%s:%d) " + "client %p refcount %d.\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), client, client->refCount)); /* This is the same thing we do if the host is locked */ @@ -1117,9 +1120,9 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host) return; afsUUID_to_string(uuid, uuid2, 127); ViceLog(125, - ("h_AddHostToUuidHashTable_r: host %" AFS_PTR_FMT " (%s:%d) added as uuid %s\n", + ("h_AddHostToUuidHashTable_r: host %p (%s:%d) added as uuid %s\n", host, afs_inet_ntoa_r(chain->hostPtr->host, hoststr), - ntohs(chain->hostPtr->port), uuid)); + ntohs(chain->hostPtr->port), uuid2)); } /* deletes a HashChain structure corresponding to this host */ @@ -1763,7 +1766,8 @@ h_GetHost_r(struct rx_connection *tcon) if (host->interface) afsUUID_to_string(&host->interface->uuid, uuid2, 127); ViceLog(0, - ("CB: new identity for host %" AFS_PTR_FMT " (%s:%d), deleting(%x %x %s %s)\n", + ("CB: new identity for host %p (%s:%d), " + "deleting(%x %p %s %s)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), identP->valid, host->interface, identP->valid ? uuid1 : "no_uuid", @@ -2106,13 +2110,13 @@ MapName_r(char *aname, char *acell, afs_int32 * aval) if (*aval == AnonymousID) { ViceLog(2, ("MapName: NameToId on %s returns anonymousID\n", - lnames.namelist_val)); + lnames.namelist_val[0])); } free(lids.idlist_val); /* return parms are not malloced in stub if server proc aborts */ } else { ViceLog(0, ("MapName: NameToId on '%s' is unknown\n", - lnames.namelist_val)); + lnames.namelist_val[0])); code = -1; } } @@ -2371,7 +2375,8 @@ h_FindClient_r(struct rx_connection *tcon) if (!oldClient->deleted) { /* if we didn't create it, it's not ours to put back */ if (created) { - ViceLog(0, ("FindClient: stillborn client %x(%x); conn %x (host %s:%d) had client %x(%x)\n", + ViceLog(0, ("FindClient: stillborn client %p(%x); " + "conn %p (host %s:%d) had client %p(%x)\n", client, client->sid, tcon, afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr), ntohs(rxr_PortOf(tcon)), @@ -2394,7 +2399,8 @@ h_FindClient_r(struct rx_connection *tcon) H_LOCK; client = oldClient; } else { - ViceLog(0, ("FindClient: deleted client %x(%x) already had conn %x (host %s:%d), stolen by client %x(%x)\n", + ViceLog(0, ("FindClient: deleted client %p(%x) already had " + "conn %p (host %s:%d), stolen by client %p(%x)\n", oldClient, oldClient->sid, tcon, afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr), ntohs(rxr_PortOf(tcon)), @@ -2463,7 +2469,7 @@ GetClient(struct rx_connection *tcon, struct client **cp) client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key); if (client == NULL) { ViceLog(0, - ("GetClient: no client in conn %x (host %s:%d), VBUSYING\n", + ("GetClient: no client in conn %p (host %s:%d), VBUSYING\n", tcon, afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr), ntohs(rxr_PortOf(tcon)))); H_UNLOCK; @@ -2471,7 +2477,7 @@ GetClient(struct rx_connection *tcon, struct client **cp) } if (rxr_CidOf(tcon) != client->sid || rxr_GetEpoch(tcon) != client->VenusEpoch) { ViceLog(0, - ("GetClient: tcon %x tcon sid %d client sid %d\n", + ("GetClient: tcon %p tcon sid %d client sid %d\n", tcon, rxr_CidOf(tcon), client->sid)); H_UNLOCK; return VBUSY; diff --git a/src/viced/viced.c b/src/viced/viced.c index 6e9bfeac1..15e9c3f22 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -423,7 +423,7 @@ setThreadId(char *s) pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)rxi_pthread_hinum); MUTEX_EXIT(&rx_stats_mutex); ViceLog(0, - ("Set thread id %d for '%s'\n", + ("Set thread id %p for '%s'\n", pthread_getspecific(rx_thread_id_key), s)); #endif } @@ -1499,8 +1499,8 @@ NewParms(int initializing) ViceLog(0, ("Read on parms failed with errno = %d\n", errno)); } else { ViceLog(0, - ("Read on parms failed; expected %d bytes but read %d\n", - sbuf.st_size, i)); + ("Read on parms failed; expected %ld bytes but read %d\n", + (long) sbuf.st_size, i)); } free(parms); return; diff --git a/src/vol/volume.h b/src/vol/volume.h index 0c7861ef8..509e7a3ff 100644 --- a/src/vol/volume.h +++ b/src/vol/volume.h @@ -914,4 +914,10 @@ extern afs_int32 VCanUseSALVSYNC(void); #define V_pref(vp,nearInode) nearInode = 0 #endif /* NEARINODE_HINT */ +hdr_static_inline(unsigned int) +afs_printable_VolumeId_u(VolumeId d) { return (unsigned int) d; } + +hdr_static_inline(unsigned int) +afs_printable_VnodeId_u(VnodeId d) { return (unsigned int) d; } + #endif /* __volume_h */